Legacy GM [SOLVED] Problem With Sprite Animation

C

ciwiaf

Guest
Hi, I have a problem with my animation when my character jump.. I have a 6 frame animation when my character jumps, then when he's falling, I have 2 frames for that. basically, every time my character jumps, the animation has a delay sometimes, like it doesn't play ASAP, also sometime it play the last frame first then start at the beginning, so it looks like he's flickering mid-air. I'm very new at GameMaker so any help would be greatly appreciated.

Here's my code for the animation:

Code:
    if grounded {
    
        sprite_index = sp_boy; //run animation
        
        }else if vsp < 0
        {
                sprite_index = sp_boy_jump; //jump animation
                
        }   
            else
        {
                sprite_index = sp_boy_fall; //fall animation
        }
 

Roderick

Member
When you change from one animation to another, GM remembers what frame of the animation you're on; it doesn't reset to 0.

So if you're on frame 6 of your run animation, and switch to the jump animation, you'll start at frame 6 of the jump animation.

Remember to reset the animation frame whenever switching animations if it's important to start from the beginning of the animation cycle.
Code:
image_index = 0;
 

jo-thijs

Member
Hi and welcome to the GMC!

I can't tell with that code what's causing the delay, but you can solve the other problem by using this code:
Code:
    if grounded {
        if sprite_index != sp_boy
            image_index = 0;
        sprite_index = sp_boy; //run animation
        }else if vsp < 0
        {
                if sprite_index != sp_boy_jump
                    image_index = 0;
                sprite_index = sp_boy_jump; //jump animation
               
        }  
            else
        {
                if sprite_index != sp_boy_fall
                    image_index = 0;
                sprite_index = sp_boy_fall; //fall animation
        }
EDIT:
@Roderick, I think you made a typo in your code.
 

jo-thijs

Member
I read sprite_index instead of image_index before.
I'm guessing you've edited it already.
Otherwise, I just misread.
 
C

ciwiaf

Guest
Hi and welcome to the GMC!

I can't tell with that code what's causing the delay, but you can solve the other problem by using this code:
Code:
    if grounded {
        if sprite_index != sp_boy
            image_index = 0;
        sprite_index = sp_boy; //run animation
        }else if vsp < 0
        {
                if sprite_index != sp_boy_jump
                    image_index = 0;
                sprite_index = sp_boy_jump; //jump animation
              
        } 
            else
        {
                if sprite_index != sp_boy_fall
                    image_index = 0;
                sprite_index = sp_boy_fall; //fall animation
        }
EDIT:
@Roderick, I think you made a typo in your code.
Thank you! these worked perfectly! I've been seeing a lot about image_index = 0 but I just don't know how to properly use it, but now i know. Thanks again!
 
Top