[Solved] wrong animation when moving

when i move the attack animation plays instead of my move animation. trying to get the hang of states.

step
Code:
switch(state)
{
    case st.normal:
    {
        scrPinputs()
        vsp = vsp + grv;
        hsp = 0
             
        if (key_left) || (key_right)
        {
            state = st.move;           
        }
       
        if (key_enter)
        {
            state = st.attack;
        }   
        sprite_index = sPYand;
        scrCollision()
        break;
    }
    case st.move:
    {
        scrPinputs()
       
        //Calculate movement
        var move = key_right - key_left;
        hsp = move * walksp;
        vsp = vsp + grv;
        if (hsp != 0) image_xscale = sign(hsp);
        image_speed = 1;
        sprite_index = sPYmove;
       
        if (hsp = 0)
        {
            state = st.normal;
        }
       
        if (key_enter)
        {
            state = st.attack;
        }          
        scrCollision()       
    }

    case st.attack:
    {
        scrPinputs()
        vsp = vsp + grv;
        {
            //Animate
            sprite_index = sPYattack;
                   
            if (image_index >= 1) && (image_index <= 3)
                {
                    instance_create_layer(x,y,layer,oHitbox)
                }
        }
        scrCollision()
    }
}
animation end
if (sprite_index == sPYattack) state = st.normal;
 

streepje8

Member
what i mostly do is check the sprite in a variable (yes thats really random :) )
here i use a tracking thing:
idle = 0
left = 1
right = 2
jump = 3
attack = 4

what i do:



[create event]
Code:
playersprite = 0;
[step event]
Code:
if(playersprite = 0)
{
sprite_index = spr_player_idle
}

if(playersprite = 1)
{
sprite_index = spr_player_left
}

if(playersprite = 2)
{
sprite_index = spr_player_right
}

if(playersprite = 3)
{
sprite_index = spr_player_jump
}

if(playersprite = 4)
{
sprite_index = spr_player_attack
}
mostly i use this with image_index but i think it should work with sprite_index too :)

EDIT: PS:to change the sprite just change the variable
 
Top