How to script a smooth jump animation in a platformer?

m11ad

Member
Hi! I was watching the tutorials for a 2d platformer. All of them were teaching simple jump animation with one or two static frames. one static frame for ascending and one for falling.
It seems the tutorials areteaching 8-bit era jumping. I have no idea how to implement a 16-bit era jump. I've seen smoother jump animation in sega mega drive than these static tutorials.

Alaaeddin jumping sprite



I know how to script a jump with two states (rise and fall) or maybe three in pseudocode:

if (player_is_grounded &and jump_button) {

image_speed = 0;

if (vertical_speed > 0) then index = fall;

if (verical_speed < 0) then index = rise;

if (-1 < vertical_speed < 1 ) then index = peak; //or something like this


But what about a jump animation with more than two static frames?like a 12 frame jump? or a jump with a peak state / land state / take-off state / the state between these states. how do you handle that animation?

For example take a look at this sprite. there is 14 frames just for falling.

Alucard Jump sprite

another example:
Sonic jump sprite


If you know how to handle the animation or have seen a tutorial for it, please recommend it!
 

Attachments

Rob

Member
If you want an animation to play from the first index and then pause at the last until the sprite is changed again, you can do something like this:

When changing state:
  • set image_index to 0
  • set image_speed to 1
  • in animation_end event: if in certain states (like jumping) set image_speed to 0 - this means that the sprite will "Freeze" on the last frame until you tell it otherwise
You can use this for some of your states.
 

m11ad

Member
If you want an animation to play from the first index and then pause at the last until the sprite is changed again, you can do something like this:

When changing state:
  • set image_index to 0
  • set image_speed to 1
  • in animation_end event: if in certain states (like jumping) set image_speed to 0 - this means that the sprite will "Freeze" on the last frame until you tell it otherwise
You can use this for some of your states.
Will this approach work on variant-height jumps that are dependant on how much you hold down the jump-key? Shouldn't the animation would be handled differently for short jumps and long jumps?
 

Roleybob

Member
It will work as long as the sprite animation always finishes before reaching the next state of the character.

If the animation hasn't finished before transitioning to the next state then it will still work but the animation will be cut short instead of playing all of the way through
 
Top