HaxeFlixel / flixel-demos

Collection of demos for HaxeFlixel
https://haxeflixel.com/demos
425 stars 290 forks source link

TurnBasedRPG: Incorrect walking animations #284

Open Poobslag opened 3 years ago

Poobslag commented 3 years ago

During the 4 - Sprites and Animation section of the TurnBasedRPG tutorial, there is some conflicting advice given:

Now, we need to define our animations. In our case, we want each animation to end with the player in their 'neutral' pose (legs together), that way each time we animate the player, it will return to the correct frame as soon as they stop animating. So, add:

animation.add("lr", [3, 4, 3, 5], 6, false); animation.add("u", [6, 7, 6, 8], 6, false); animation.add("d", [0, 1, 0, 2], 6, false);

This advice implies that these animations will end with the player in their 'neutral' pose. However, visual examination of the player.png image referenced by the tutorial reveals that the neutral animation frames are frames 0, 3 and 6 -- not 5, 8 and 2. This can also be demonstrated by playing the HTML5 TurnBasedRPG in a browser (https://haxeflixel.com/demos/TurnBasedRPG/). After moving the player, they end their animation with one leg sticking out.

This can be corrected by applying the following diff, which moves the first frame in the animation to the end:

diff --git a/Tutorials/TurnBasedRPG/source/Player.hx b/Tutorials/TurnBasedRPG/source/Player.hx
index 567727e3..801a321d 100644
--- a/Tutorials/TurnBasedRPG/source/Player.hx
+++ b/Tutorials/TurnBasedRPG/source/Player.hx
@@ -18,9 +18,9 @@ class Player extends FlxSprite
                loadGraphic(AssetPaths.player__png, true, 16, 16);
                setFacingFlip(FlxObject.LEFT, false, false);
                setFacingFlip(FlxObject.RIGHT, true, false);
-               animation.add("lr", [3, 4, 3, 5], 6, false);
-               animation.add("u", [6, 7, 6, 8], 6, false);
-               animation.add("d", [0, 1, 0, 2], 6, false);
+               animation.add("lr", [4, 3, 5, 3], 6, false);
+               animation.add("u", [7, 6, 8, 6], 6, false);
+               animation.add("d", [1, 0, 2, 0], 6, false);

                drag.x = drag.y = 1600;
                setSize(8, 8);
Geokureli commented 3 years ago

even with this fix I don't like how the walking animation plays a full loop after you stop walking. typically I'll make a walk and an idle anim and switch between them like so:

animation.add("walk_lr", [4, 3, 5, 3], 6);
animation.add("walk_u", [7, 6, 8, 6], 6);
animation.add("walk_d", [1, 0, 2, 0], 6);
animation.add("idle_lr", [3])
animation.add("idle_u", [6]);
animation.add("idle_d", [0]);

also how did you show that diff text with github's markdown?

Poobslag commented 3 years ago

I used the git diff command to generate that output.