Below is my current code for movement. I would like the actor to face in the direction of movement. For example if the up arrow is pressed, the actor will move north and the image for that actor will turn to face north.
Here is my current code:
1 2 3 4 5 6 7 | public void moveAndTurn() { if (Greenfoot.isKeyDown( "up" ))setLocation(getX(),getY()- 1 ); if (Greenfoot.isKeyDown( "down" ))setLocation(getX(), getY()+ 1 ); if (Greenfoot.isKeyDown( "left" ))setLocation(getX()- 1 , getY()); if (Greenfoot.isKeyDown( "right" ))setLocation(getX()+ 1 , getY()); } |