1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 [Resolved] Sprite Jitters Help

Discussion in 'Programming' started by MrJellybelly, Feb 23, 2018.

  1. MrJellybelly

    MrJellybelly Guest

    Hey there, I'm pretty new to GML and coding in general so I've been practicing with a project and I've noticed something very strange I haven't been able to fix/understand.
    My player object has various fighting moves tied to their own states and scripts. Some of the moves can only be performed on specific frames of animation and for the most part that works fine however It seems like the animations start from the frame a previous animation had ended.
    So if I'm running and I press punch on frame 3, instead of the punch animation starting at frame 1, it starts from frame 3 and ends quicker than expected. Any ideas to fix this?

    Here's the script I have for idle;
    Code:
    // Sprite Control
    if (yprevious != y)
    {
        sprite_index = spr_joe_jump;
        image_speed = 0;
        image_index = y > yprevious;
    } else {
        if (xprevious != x)
        {
            sprite_index = spr_joe_walk;
            image_speed = 0.3;
        } else {
            sprite_index = spr_joe_stand;
        }
    }
    
    
    if (xprevious < x)
    {
        image_xscale = 1;
    } else if (xprevious > x) {
        image_xscale = -1;
    }
    
    if (key_down)
    {
        if(place_meeting(x,y+1,obj_wall))
        {
            state = states.duck
        } else {
            {
                vsp = 6
            }
        }
    }
    
    // Attacking
    if (key_attack)
    {
        if(place_meeting(x,y+1,obj_wall))
        {
            state = states.attacking;
        } else {
            {
                state = states.airstrike;
            }
        }
    }
    
    // Dodge
    if (key_guard)
    {
        if(place_meeting(x,y+1,obj_wall))
        {
            state = states.guard;
        }
    }
    
    
    if (stun = 1)
    {
        state = states.hitstun;
    }
    

    And here's one of my attack scripts;
    Code:
    scr_input();
    
    if(key_right)
    {
        if (hsp < .5)
        {
        state = states.smash
        } else {
            state = states.dashatk
        }
    }
    
    if(key_left)
    {
        if (hsp > -.5)
        {
        state = states.smash
        } else {
            state = states.dashatk2
        }
    }
    
    if(key_up)
    {
        state = states.doublejump
    }
    
    hsp = 0;
    vsp = 0;
    
    
    // Animation
    sprite_index = spr_joe_jab;
    image_speed = 0.3;
    
    // Hitbox
    if (image_index >= 3) && (image_index <=12)
    {
        with (instance_create(x,y,obj_joe_vulcan_hitbox))
        {
            image_xscale = other.image_xscale;
            with (instance_place(x,y,obj_player2))
            {
                if (stun = 0)
                {
                    hp -= .5;
                    stun = 1;
                }
            }
        }
    }
    
    if (keyboard_check(ord("Z")))
    {
        if (image_index >= 9) && (image_index <=11)
        {
            state = states.flurry
        }
    }
    
    if (stun = 1)
    {
        state = states.hitstun;
    }
    I know it's a little messy but I'm still only starting out :-')
    Hopefully this gives you an idea of what I'm dealing with. Thanks very much for your help!
     
  2. JFitch

    JFitch Member

    Joined:
    Sep 28, 2016
    Posts:
    428
    When changing sprites, if the image index exists in the new sprite, it is not reset. If you want to reset the image index, put this at the end of your code.
    Code:
    if (sprite_index != sprite_previous) {
        image_index = 0;
        sprite_previous = sprite_index;
        }
    Just set sprite_previous to sprite_index in your create event.
     
  3. Pyxus

    Pyxus Member

    Joined:
    Nov 6, 2016
    Posts:
    195
    Hey, don't have the time right now to closely inspect your code but double check to make sure you're resetting your image index index before running your punch code. My guess is you're changing your sprite index while keeping the image index the same.
     
  4. MrJellybelly

    MrJellybelly Guest

    Well that was easy lol. Thanks! It seemed to work for everything but my dash attack however, I solved that pretty easy. for some reason, the animation was playing backwards. Probably my previous attempt to fix this very problem.
    Thanks a lot!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice