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)
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
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;
}