HaxeFlixel / flixel-docs

Documentation for HaxeFlixel
72 stars 135 forks source link

Tutorial Pt. 4 contains sprite animation error #237

Open Prid13 opened 4 years ago

Prid13 commented 4 years ago

Part 4 - "Sprites and Animation" contains a slight error in the code.

In step 3, the code is supposed 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"

However, that doesn't seem to be working. After moving, the animation always stops on the last frame where one leg is out. Maybe the player sprite got updated after the tutorial and the frames changed?

Either way, the solution is simply to move the first frame numbers in each array to the very end of the array, like this:

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);

That way the animation sequence will end with the neutral pose.


Another solution I found online was to add the code below after if(up || down || left || right){:

else if(animation.curAnim!=null)
{
    animation.curAnim.curFrame = 0;
    animation.curAnim.pause();
}
NQNStudios commented 3 years ago

I ran into the same problem, and also, the demo that shows the finished game here does. And so does the gif here

So this would need to be fixed in the tutorial, the gif, and the actual source code of flixel-demos here

Assuming fixing it in flixel-demos would propogate to the host of the IFrame here then I think everything would be fine.

I agree that the animation code needs to be explained more, per #241. Fixing this could be a good time to do that. I could PR flixel-docs and flixel-demos to do the work.