flixel
flixel copied to clipboard
Update the official tutorial, "Groundwork" part
Discussed in https://github.com/HaxeFlixel/flixel/discussions/2521
Originally posted by NicklGames March 16, 2022 Let me explain myself
If following the tutorial, when reaching this part
this will cause a bug, in which player will constantly move because it's telling to move the player every frame with no condition
It can be easily fixed tho, in 2 ways i know
1: Setting the speed to something only when player is moving and setting it to 0 when player is not

2: Adding a boolean that will tell if player is actually moving and move the player only if any of the keys is actually pressed

It really is easy, why not update the tutorial (if the reason that it IS easy, then why letting an intentional bug be in an OFFICIAL tutorial?)
I don't think so, if you have checked the project the tutorial made, you'll find that the Player.hx uses the same code the tutorial have shown.
the reason that cause the player moves in a certain direction constantly is probably that you forgot to set the drag.x = drag.y = 1600 (which has described earlier in this chapter this tutorial)?
and there's another thing, you'll have to put velocity.set(SPEED,0) and velocity.rotate(FlxPoint.weak(0,0), newAngle) inside the if (up || down || left || right) condition due to only execute it only if player pressed the move keys.
thus if the player not pressing any move keys, the velocity is affected by the drag.x = drag.y = 1600 and it will go back to 0, then the character will stop moving
I'll add this to the 5.0.0 release. It might be time to revisit this tutorial from the ground up, since newcomers seem to have a lot of friction.
Hi! @Geokureli , I did checked the discussion #2521 and Im pretty sure the tutorial is correct, the thing is that reader may easily forgot to put velocity.set() and velocity.rotate() inside the if() body that described on 6th step the tutorial shown.
However, this tutorial has been there for a long time, it would be great to have something new for the newcomers tho :D
I think the tutorial should be revisited, this part here is quite clunky and only serves to confuse the learner with how roundabout it is for such a basic function. but also yes, we should add new tutorials as well