I do it with an enum for the Animations:
enum ANIMATION {
WALKDOWN = 0,
WALKUP = 180,
WALKX = 90,
WALKXF = 270,
}
When the Player moves down he is in the WALKDOWN Animation:
if movement.y > 0:
animation.play("walkdown")
G.player_animation = ANIMATION.WALKDOWN
Then I say, when he is in this Animation and the movement is Zero, the Player has to Play the Idle-animation:
if G.player_animation == ANIMATION.WALKDOWN and movement == Vector2.ZERO:
animation.play("idledown")
if G.player_animation == ANIMATION.WALKUP and movement == Vector2.ZERO:
animation.play("idleup")
if G.player_animation == ANIMATION.WALKX and movement == Vector2.ZERO:
animation.play("idlex")
if G.player_animation == ANIMATION.WALKXF and movement == Vector2.ZERO:
animation.play("idlex")
I have the player_animation in a Global script because I need it for Scene changing.