How do i make object to move from left to right? (that it will repeat it)
Also to go from up to down.


public void moveRight() { int x = (getX() + 5); int y = (getY()); setLocation(x, y); } public void moveLeft() { int x = (getX() - 5); int y = (getY()); setLocation(x, y); } public void moveDown() { int x = (getX()); int y = (getY() + 5); setLocation(x, y); } public void moveUp() { int x = (getX()); int y = (getY() - 5); setLocation(x, y); }
public void moveOnKeyPress() { if(Greenfoot.isKeyDown("left")) { moveLeft(); } if(Greenfoot.isKeyDown("right")) { moveRight(); } if(Greenfoot.isKeyDown("up")) { moveUp(); } if(Greenfoot.isKeyDown("down")) { moveDown(); } }