-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add documentation on flipping for diagonal movement in 'First 2D Game" tutorial #11487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Falco-Boehnke
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
Falco-Boehnke:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -323,6 +323,53 @@ movement. Let's place this code at the end of the ``_process()`` function: | |||||
| Play the scene again and check that the animations are correct in each of the | ||||||
| directions. | ||||||
|
|
||||||
|
|
||||||
| You may notice that the animations for moving diagonally are not yet all aligned | ||||||
| with the animation for moving straight down. As a result, the player may appear to flip | ||||||
| incorrectly or play the wrong animation when switching from moving down to diagonally down. | ||||||
|
|
||||||
| To correct this, we also need to check for cases where multiple movement keys are pressed | ||||||
| at the same time. Based on the direction the player is moving, we can then adjust the | ||||||
| animation’s flip settings using the same boolean checks we used earlier. This ensures the | ||||||
| correct animation is displayed no matter which combination of inputs the player uses. | ||||||
|
|
||||||
| .. tabs:: | ||||||
| .. code-tab:: gdscript GDScript | ||||||
|
|
||||||
| if(velocity.x != 0 && velocity.y !=0): # If vertical and horizontal movement keys are pressed | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $AnimatedSprite2D.animation = "walk" | ||||||
| $AnimatedSprite2D.flip_h = velocity.x < 0 | ||||||
| $AnimatedSprite2D.flip_v = velocity.y > 0 | ||||||
| elif 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 : | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $AnimatedSprite2D.animation = "up" | ||||||
| $AnimatedSprite2D.flip_v = velocity.y > 0 | ||||||
|
|
||||||
| .. code-tab:: csharp | ||||||
|
|
||||||
| if (velocity.X != 0 && velocity.Y != 0) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| animatedSprite2D.Animation = "walk"; | ||||||
| animatedSprite2D.FlipH = velocity.X < 0; | ||||||
| animatedSprite2D.FlipV = velocity.Y > 0; | ||||||
| } | ||||||
| else if (velocity.X != 0) | ||||||
| { | ||||||
| animatedSprite2D.Animation = "walk"; | ||||||
| animatedSprite2D.FlipV = false; | ||||||
| // See the note below about the following boolean assignment. | ||||||
| animatedSprite2D.FlipH = velocity.X < 0; | ||||||
| } | ||||||
| else if (velocity.Y != 0) | ||||||
| { | ||||||
| animatedSprite2D.Animation = "up"; | ||||||
| animatedSprite2D.FlipV = velocity.Y > 0; | ||||||
| } | ||||||
|
|
||||||
| .. tip:: A common mistake here is to type the names of the animations wrong. The | ||||||
| animation names in the SpriteFrames panel must match what you type in | ||||||
| the code. If you named the animation ``"Walk"``, you must also use a | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.