Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions getting_started/first_2d_game/03.coding_the_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if velocity.x != 0:
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";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}
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.
Comment on lines 302 to 303
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
animatedSprite2D.FlipV = false;
// See the note below about the following boolean assignment.
// See the note below about the following boolean assignment.
animatedSprite2D.FlipV = false;

Or flip the order above in GDScript

animatedSprite2D.FlipH = velocity.X < 0;
}
else if (velocity.Y != 0)
if (velocity.Y != 0)
{
animatedSprite2D.Animation = "up";
animatedSprite2D.FlipV = velocity.Y > 0;
}

Expand Down