• 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!

Legacy GM [Resolved] Sprite Jitters Help

M

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!
 
J

JFitch

Guest
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.
 
P

Pyxus

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!
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.
 
M

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!
 
Top