godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.77k stars 3.06k forks source link

An error in getting_started/first_2d_game/03.coding_the_player #8698

Open MartianReunion opened 8 months ago

MartianReunion commented 8 months ago

This issues uses machine translation

Description

In the Choosing animations section, there is the following code

if velocity.x != 0:
    $AnimatedSprite2D.animation = "walk"
    $AnimatedSprite2D.flip_v = false
    # See the note below about boolean assignment.
    $AnimatedSprite2D.flip_h = velocity.x < 0
elif velocity.y != 0:
    $AnimatedSprite2D.animation = "up"
    $AnimatedSprite2D.flip_v = velocity.y > 0

I think it does not fulfill the intended function If you want to make a move down to the left or right, it doesn't flip up and down, I think it needs to be changed to the following code to achieve the desired effect.

if velocity.x != 0:
    $AnimatedSprite2D.animation = "walk"
elif velocity.y != 0:
    $AnimatedSprite2D.animation = "up"
if velocity.x != 0 or velocity.y != 0: 
    $AnimatedSprite2D.flip_h = velocity.x < 0
    $AnimatedSprite2D.flip_v = velocity.y > 0
MartianReunion commented 8 months ago

Here's the link: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/03.coding_the_player.html