June 2018
Beginner to intermediate
298 pages
7h 38m
English
Now that the player can move, you need to change which animation the AnimatedSprite is playing based on whether it is moving or standing still. The art for the run animation faces to the right, which means it should be flipped horizontally (using the Flip H property) for movement to the left. Add this to the end of your _process() function:
if velocity.length() > 0: $AnimatedSprite.animation = "run" $AnimatedSprite.flip_h = velocity.x < 0 else: $AnimatedSprite.animation = "idle"
Note that this code takes a little shortcut. flip_h is a Boolean property, which means it can be true or false. A Boolean value is also the result of a comparison like <. Because of this, we can set the property equal to the result of the comparison. ...
Read now
Unlock full access