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

2014/6/5

How to make an actor move slower than 1pixel per act?

5GosdsJa 5GosdsJa

2014/6/5

#
I need to make an actor move slower than 1pixel per act. I am using the "move()" method but it does not allow fractions, only full numbers. I tried to find how to fix this before and there was something about delaying acts that looked like a solution but im not sure how to implement it.
dan11 dan11

2014/6/5

#
Import the SmoothMover class. It has a move(double) method that allows for decimal movements To get it, go edit, import class, SmoothMover. Then, in the code for the Actor that you want to move decimal numbers, instead of public class (insert actor here) extends Actor, put public class (insert actor here) extends SmoothMover. Alternatively, simply import SmoothMover first, and then add a subclass of SmoothMover
dan11 dan11

2014/6/5

#
Alternatively, you could use Greenfoot.delay(), put that won't look very good if other things are supposed to be moving as normal
5GosdsJa 5GosdsJa

2014/6/5

#
thank you that works good. Now i am trying to have the speed in an integer so the speed can change when certain events occur. Heres the code:
private int asteroidSpeed = 0.5;
public void act() 
{
        move(asteroidSpeed);
}
i get an error saying "possible loss of precision, required; found: double" when asteroidSpeed = a decimal but not when its a full number. Do you know how i can fix this?
davmac davmac

2014/6/5

#
i get an error saying "possible loss of precision, required; found: double"
I don't think that's the full error message! "required: int, found: double" You are declaring the variable to be an int - i.e. an integer, a whole number - and then you are trying to assign a decimal fraction to it. Declare the variable as a double!
private double asteroidSpeed = 0.5;
You need to login to post a reply.