Dr_Nomz
Member
I'm trying to have an enemy attack, and then switch back to it's normal state after attacking. Problem is I can't figure out how to make it play the animation properly. It'll start, stay on the first frame, and do nothing.
I start off in the CREATE event with a simple state engine, one for attacking, one for normal action.
After that I use the step event to hit a simple key (for testing) to make the enemy attack.
If the key is pressed, the enemy switches to an attack state, which is handled in the draw event:
And the enemy is supposed to switch back to it's normal state after the animation plays out. (animation end event)
But when I press the key, it just switches to the first frame of the animation and does nothing. Why isn't it playing?
I start off in the CREATE event with a simple state engine, one for attacking, one for normal action.
GML:
///state
enum enemy_state{
normal,
attack
}
state = enemy_state.normal;
GML:
///STEP
if keyboard_check_pressed(vk_space){
state = enemy_state.attack
}
GML:
///DRAW
if state = enemy_state.normal{
draw_sprite_ext(spr_Enemy,image_index,x,y,1,1,0,c_white,1);
}
if state = enemy_state.attack{
draw_sprite_ext(spr_Attack,image_index,x,y,1,1,0,c_white,1);
}
GML:
if sprite_index == spr_Attack{
state = enemy_state.normal
}