• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How can i manage a jump animation ?

esem.JPG

in my Idle state:

Code:
if (ground && keyjump)
{
vsp=-vspmax;

state=states.jump;   
}
My jump state

Code:
sprite_index=spr_player_jump;
if (!ground && vsp>0)
{ state=states.falling; }

//move air dx sx
if (!ground && move!=0)
{
image_xscale=move;
if (move==1)
{    hsp=scr_approach(hsp*0.85,hspmax*move,airacceleration); }

if (move==-1)
{ hsp=scr_approach(hsp*0.85,hspmax*move,airacceleration); }   
}

// little jump
if (keyjumprelease)
{
if (vsp<0)
{
vsp *=0.5;
}
}

//double jump
if (keyjump && !ground && djump>0)
{
vsp=-vspmax*percentualedoppiosalto;
djump--;}
Falling State
Code:
sprite_index=spr_player_falling;

if (ground)
{
    //double jump reset
    if (djump==0)
    {        djump++;    }
    
    state=states.idle;
}

if (!ground && move!=0)
{
    image_xscale=move;
    
    if (move==1)
    {         hsp=scr_approach(hsp*0.85,hspmax*move,airacceleration); }
    
    if (move==-1)
    {         hsp=scr_approach(hsp*0.85,hspmax*move,airacceleration);  }   
}
 

Hyomoto

Member
Well, I can't make too many suggestions just based on the code you have here honestly. Mostly because I'm not *quite* sure what your end result is. It has a 2D beat-em-up or even a 2D fighting game appearance, so if you go back to a lot of 8 and 16 bit style games, you'll see the animation always plays fully. That is to say, there isn't a lot of platforming in those styles of games so the expectation is that the entire animation will play from beginning to end. If that's the case, you should be able to determine what frame to display based on what point in the jump you are currently at. I'm not sure if you've considered this already, but if you are using the built-in animation system it may not be the best way to control this. If you take control of which frame is being displayed manually:
Code:
jumpFrame = ( y - jumpStartY ) div 2;

draw_sprite( sprite_index, jumpFrame, x, y );
You can base your frame on the height of the jump. Obviously this is a generic suggestion. Another option would be to use keyframe data:
Code:
animation = [ 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0];

draw_sprite( sprite_index, animation[ frame ], x, y );
Or event just a timer of some sort. Again, just a generic suggestion but might get you thinking about ways to handle this.
 
Top