[SOLVED] drive and attack

RODO

Member
hello guys, I'm having a little sprite problem. I am trying to make my character walk and attack while walking, well it works and I did it but the visual part I am having difficulty

I have a sprite for him to stop attacking and another one for him walking and attacking, the problem is: he alternates between these two (I'll put my code down for better understanding)
GML:
//STEP EVENTE
up = keyboard_check(ord("W"))
down = keyboard_check(ord("S"))
right = keyboard_check(ord("D"))
left = keyboard_check(ord("A"))
v_ = (down - up) * vel;
h_ = (right - left) * vel;

var attack = mouse_check_button(mb_left);


if(h_speed != 0)
{
    image_xscale = sign(h_speed);   
}

switch(estado_player)
{
    case "parado":
    sprite_index  = spr_player_parado;
    h_speed = 0;
    v_speed = 0;
    
    if(v_ != 0 or h_ != 0)
    {
        estado_player = "mover";   
    }
    
    if(attack)
    {
        estado_player = "attack";   
    }
    
    break;
    
    case "mover":
    //evitando que o player ande no estado de attack
    nao_posso_andar = false;
    sprite_index = spr_player_andando;
    
    if(abs(v_) < 0.5 && abs(h_) < 0.5)
    {
        estado_player = "parado";   
    }
    
    
    if(attack)
    {
        
        estado_player = "attack";   
    }
    
    break;
    
    case "attack":
    
    
    // check if the sprite has changed and reset image_index
    if (ultima_sprite != sprite_index)
    {
         sprite_index = spr_player_attack;
         image_index = 0; // here resets the sprite frame number
         ultima_sprite=sprite_index; // here it leaves "ultimosprite" equal to sprite_index.
        
    }
    
    if(image_index == 2)
    {
        var hit = instance_create_layer(mouse_x,mouse_y,"player",obj_hitbox);
        hit.dano = 5;
    }
    
    if(attack && h_speed != 0 && v_speed != 0)
    {
        sprite_index = spr_player_andando_attack;   
    }
    
    if(image_index >= image_number - 1)
    {
        estado_player = "mover";
    }
    break;
    
}
have any possibility of making this animation or my code needs to be redone or ... I don't know, I am grateful for any help
 

Nidoking

Member
I'm pretty sure your issue is that you're manipulating sprite_index and image_index in the middle of all of this processing. You should handle the state logic separately from the graphics logic.
 

RODO

Member
I'm pretty sure your issue is that you're manipulating sprite_index and image_index in the middle of all of this processing. You should handle the state logic separately from the graphics logic.
hmmmm what you want to tell me is that: do i have to make a dedicated system just for the graphic of the character ? and not all together ?
 
Top