diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index 2548f77ffad..26a1e4085b8 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -271,28 +271,40 @@ movement. Let's place this code at the end of the ``_process()`` function: .. tabs:: .. code-tab:: gdscript GDScript - if velocity.x != 0: $AnimatedSprite2D.animation = "walk" - $AnimatedSprite2D.flip_v = false - # See the note below about the following boolean assignment. - $AnimatedSprite2D.flip_h = velocity.x < 0 elif velocity.y != 0: $AnimatedSprite2D.animation = "up" - $AnimatedSprite2D.flip_v = velocity.y > 0 + + # Allow the character to flip in both directions. + if velocity.x != 0: + # See the note below about the following boolean assignment. + $AnimatedSprite2D.flip_v = false + $AnimatedSprite2D.flip_h = velocity.x < 0 + if velocity.y != 0: + $AnimatedSprite2D.flip_v = velocity.y > 0 .. code-tab:: csharp if (velocity.X != 0) { animatedSprite2D.Animation = "walk"; + + } + else if (velocity.Y != 0) + { + animatedSprite2D.Animation = "up"; + } + + # Allow the character to flip in both directions. + if (velocity.X != 0) + { animatedSprite2D.FlipV = false; // See the note below about the following boolean assignment. animatedSprite2D.FlipH = velocity.X < 0; } - else if (velocity.Y != 0) + if (velocity.Y != 0) { - animatedSprite2D.Animation = "up"; animatedSprite2D.FlipV = velocity.Y > 0; }