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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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()); } } |