Skip to content

Commit 2df48fa

Browse files
Allow the character to flip in both directions #11347 (c# code)
1 parent e1b2f0f commit 2df48fa

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

getting_started/first_2d_game/03.coding_the_player.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ movement. Let's place this code at the end of the ``_process()`` function:
276276
elif velocity.y != 0:
277277
$AnimatedSprite2D.animation = "up"
278278

279-
# Allow the character to flip in both directions
279+
# Allow the character to flip in both directions.
280280
if velocity.x != 0:
281281
# See the note below about the following boolean assignment.
282282
$AnimatedSprite2D.flip_v = false
@@ -289,13 +289,22 @@ movement. Let's place this code at the end of the ``_process()`` function:
289289
if (velocity.X != 0)
290290
{
291291
animatedSprite2D.Animation = "walk";
292+
293+
}
294+
else if (velocity.Y != 0)
295+
{
296+
animatedSprite2D.Animation = "up";
297+
}
298+
299+
# Allow the character to flip in both directions.
300+
if (velocity.X != 0)
301+
{
292302
animatedSprite2D.FlipV = false;
293303
// See the note below about the following boolean assignment.
294304
animatedSprite2D.FlipH = velocity.X < 0;
295305
}
296-
else if (velocity.Y != 0)
306+
if (velocity.Y != 0)
297307
{
298-
animatedSprite2D.Animation = "up";
299308
animatedSprite2D.FlipV = velocity.Y > 0;
300309
}
301310

0 commit comments

Comments
 (0)