GMS 2 Four-part jumping animation

RacieB

Member
I'm having a ton of trouble figuring out how to go about doing a complex jump animation. If it was just two parts, rising and falling, that would be really easy and I could handle that in her "bit_jump_state" script something like
Code:
if vsp < 0 image_index = 0 else image_index = 1;
or
Code:
if vsp < 0 sprite_index = s_bit_jump_rise else sprite_index = s_bit_jump_fall;
but my character animation is actually set up like this -

bitjump.png

- where she has "begin to jump", "rising", "falling", and "landing" frames. What's the best way to handle this? Is it feasible to use one animation / state, should it be split into four, etc? I also don't want any of the sections to loop animation (well, maybe the latter two frames of "rising" but I may cut one of those anyway since they're very similar.)
 

Nidoking

Member
I would just use the "begin jump" animation when you start jumping, then switch to the "jumping" once that ends. Once the character starts to descend, switch to "falling", and either switch to "landing" after hitting the ground or when the collision with the ground is imminent.
 

RacieB

Member
I would just use the "begin jump" animation when you start jumping, then switch to the "jumping" once that ends. Once the character starts to descend, switch to "falling", and either switch to "landing" after hitting the ground or when the collision with the ground is imminent.
This seems to be sort of working... in her jump_state script, I have
Code:
if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed {
    image_index = 6;
}
and that stops her at the peak of her jump like it's supposed to. However, in her anim script I have
Code:
case states.JUMP:
        if vsp > 0 sprite_index = s_bit_jump_fall;
        if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed {
            image_index = 1;
        }
    break;
which does switch her to her falling sprite, but doesn't stop animating it between the two frames.
 

Nidoking

Member
Well, if you don't want the image_index to change, you can change the image_speed to 0 and then back to 1 when you switch sprites again.
 

RacieB

Member
Hmm.... even when I set the speed to 0 it still animates! I think it's completely ignoring my check for when the fall hits the end of its animation, but I'm not sure why...
 

RacieB

Member
I have two scripts right now that control her jumping animations;

this one is when jump button has been pressed or held
Code:
///bit_jump_state();
//get input
get_input();

//calculate movement
calc_movement();

//check state
if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed {
    image_index = 6;
}

if on_ground() {
    if hsp != 0 state = states.RUN else state = states.IDLE;
    //create dust if landing
    if vsp > 0 {
        effect_create_above(ef_smoke, x - 30, y, 1, c_white);
        effect_create_above(ef_smoke, x, y, 1, c_white);
        effect_create_above(ef_smoke, x + 30, y, 1, c_white);
    }
}

if attack {
    state = states.ATTACK;
    image_index = 0;
}

//enable smaller jumps
if vsp < 0 and !jump_held vsp = max(vsp, jump_spd/jump_dampner);

//apply movement
collision();

//apply animation
anim();
this one is to handle complicated animation states (like when she attacks in midair or while running, but that hasn't been added in yet)
Code:
///anim();
sprite_index = sprites_array[state];
mask_index = mask_array[state];
image_xscale = facing;

switch(state) {
    case states.JUMP:
        if vsp > 0 sprite_index = s_bit_jump_fall;
        if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed {
            image_index = 1;
        }
    break;
}
I can tell that it just keeps on running the anim() script over and over again, but I'm not certain why it's completely ignoring the line telling it to stop animating (whether I make that image_index = 1 or image_speed = 0, it completely ignores it and loops the two frames.)
 

Nidoking

Member
//check state
if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed {
image_index = 6;
}
Well, right here, you're manipulating the image_index directly. Presumably, 6 is less than whatever image_number - sprite_get_speed(sprite_index)/room_speed happens to be, so when you get to that same check in the anim() script, it's always false. That's why it's ignoring the line - you told it to.
 

RacieB

Member
omg... just tested telling the jump animation to stop at frame 1 rather than 6, and both animations stopped at frame 1... changing that it to "if sprite_index != s_bit_jump_fall and image_index >= image_number - sprite_get_speed(sprite_index)/room_speed" makes it behave correctly šŸ˜„

Now I only have to figure out how to get her to play the landing animation, that's going to be much more annoying. I know logically it would be like, "if you're falling, check if there's a solid tile a little under you and switch sprite to 's_bit_jump_land'" but I'm not quite sure where to start with that...
 

Nidoking

Member
I presume you already check somewhere to see whether you're landing on the ground, probably in collision(). That might be a good place to start.
 
Top