I'm having difficulty using the keyboard to move an actor one square at a time. At the moment it responds to the keyboard input fine but jumps several cells in the process. My code for this actor is:
How can I fix it so that it only moves one cell at a time?
Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public void act() { if (Greenfoot.isKeyDown( "up" )){ setLocation(getX(), getY() - 2 ); } if (Greenfoot.isKeyDown( "down" )){ setLocation(getX(), getY() + 2 ); } if (Greenfoot.isKeyDown( "left" )){ setLocation(getX() - 2 , getY()); } if (Greenfoot.isKeyDown( "right" )){ setLocation(getX() + 2 , getY()); } } |