I am making a Super Mario like 2D platformer and I've encountered a problem. I need to move this sprite :
When a player presses the right key, the sprite moves by 32 px to the right. The process of moving the sprite is as follows :
- The sprite begins in a
StandingIdleFirstStep
state (Image 1). - Then the sprite enters a transition state (Image 2). The sprite is moved by 16 px to the right. This state is visible for 256 ms.
- Finally, the sprite ends the movement in a
StandingIdleSecondStep
and has moved 32 px from its starting position (Image 3 - first and third step images differ).
During this entire process, the user cannot interact with the sprite. I can feed the process with a approx. 30 ms delta per frame.
Currently I'm thinking about this solution :
- User presses move right
- Set
moving
flag totrue
- Move sprite by
x+=16 px
. - Update sprite animation
- Draw everything
(after 256 ms)
- Check
if currentAnimationImageIndex % 2 == 1
. - If true (odd image, can't stop there), move sprite by another
x+=16 px
. - Update sprite animation
- Draw everything
- Set
moving
flag tofalse
StandingIdleFirstStep
andStandingIdleSecondStep
to the animaton cycle (add time to their images) the process gets messed up (the cycle waits until the display time passes). If I don't add those two states to the animation, then what should I do with them? \$\endgroup\$ – dØd Jun 16 '13 at 18:18