How can make an object move and down, but when the object is moving up it should be slower then when its coming down. (coming down should be faster)
// with these instance fields private int hiY; // the higher y-limit private int, loY; // the lower y-limit private int speed; // the rate of movement // use this in act method if (speed == -1 && getY()<=hiY) speed = 2; if (speed == 2 && getY()>=loY) speed = -1; setLocation(getX(), getY()+speed;
// with these instance fields private int hiY; // the higher y-limit private int, loY; // the lower y-limit private int speed; // the rate of movement // use this in act method if (speed == -1 && getY()<=hiY) speed = 2; if (speed == 2 && getY()>=loY) speed = -1; setLocation(getX(), getY()+speed;
import greenfoot.*; public class Platform extends Actor { private int hiY; private int loY; private int speed; public Platform(int hiLoc, int loLoc) { hiY = hiLoc; loY = loLoc; speed = -1; // code constructing the platform objects if needed } public void act() { if (speed == -1 && getY() <= hiY) speed = 2; if (speed == 2 && getY() >=loY) speed = -1; setLocation(getX() getY()+speed); } }
import greenfoot.*; public class Platform extends Actor { private int hiY; private int loY; private int speed; public Platform(int hiLoc, int loLoc) { hiY = hiLoc; loY = loLoc; speed = -1; // code constructing the platform objects if needed } public void act() { if (speed == -1 && getY() <= hiY) speed = 2; if (speed == 2 && getY() >=loY) speed = -1; setLocation(getX() getY()+speed); } }