I'm making a simple game with GIF animations. I would like to have the character look left when the last key pressed was the predefined left key. I just need the programme to memorize the last key and if it equals l it's the standingL animation that should play: Here's what I've come with:
This code doesn't work, can anyone help me please?
String l = "a"; //key to move left
String r = "d"; //key to move right
String lastKey = Greenfoot.getKey();
if(onGround() == true
&& !Greenfoot.isKeyDown(r)
&& !Greenfoot.isKeyDown(l))
{
if(lastKey != null){
if(lastKey.equalsIgnoreCase(l))
{
setImage(standingL.getCurrentImage());
}
if(lastKey.equalsIgnoreCase(r))
{
setImage(standing.getCurrentImage());
}
} else{
setImage(standing.getCurrentImage());
}
}
