This site requires JavaScript, please enable it in your browser!
Greenfoot back
polar568
polar568 wrote ...

2014/3/9

Using doubles in movement

polar568 polar568

2014/3/9

#
I am wanting to have an object move slower than move(1), but I am not sure what methods I would use to achieve this. I looked through the API and I can't seem to find any movement methods that allow for doubles. I could just be missing something, so if a point in the right direction would solve my problem that would be great as well!
danpost danpost

2014/3/9

#
You could either keep track of your coordinate location in double fields or continue to use int fields but multiply them by, say 10, and when setting coordinate locations, divide by 10. This second way would allow movement up to 10 times slower than normal.
polar568 polar568

2014/3/9

#
How would I keep track of the coordinates in double fields? Nevermind, I figured it out myself.
Zamoht Zamoht

2014/3/9

#
In the class that should move slower you want to add the following: private double dX, dY; public void setLocation(double x, double y) { dX = x; dY = y; super.setLocation((int)Math.round(x), (int)Math.round(y)); } This should work. I may have missed something since I'm a little tired, but it's pretty simple so you should be able to work it out from this.
polar568 polar568

2014/3/10

#
Thanks! I just used the SmoothMover class and this helps clear it up how it works!
You need to login to post a reply.