[Solved] Enemy animation won't play

A

AwesomeAlvin

Guest
Code:
///scr_zombie_attack
var dis = point_distance(x,y, obj_player.x, obj_player.y);

if (dis > attackRange) {
    state = enemyState.FOLLOW;
} else {
    sprite_index = spr_zombie1_attack;
    speed = 0;
    image_speed = 0.16;
    image_index = 0;
    if (image_index >= 5) {
     // state = enemyState.FOLLOW;
    }
}
So this is a script that is called when the enemy's state becomes 'attack'. I know this code is called, because if I set obj_player.hp -= 20; in the else section, I lose HP when I get close to the enemies. However, they don't play the animation, and I can't figure out why.

Any help would be appreciated!
Please let me know if I have to provide more information

thank you!
 
In your "else" section you are setting the image_index to 0 every time. It can't get off the first image in the spr_zombie_attack.
Code:
///scr_zombie_attack
var dis = point_distance(x,y, obj_player.x, obj_player.y);

if (dis > attackRange) {
   state = enemyState.FOLLOW;
} else {
   sprite_index = spr_zombie1_attack;
   speed = 0;
   image_speed = 0.16;
   image_index = 0;              <======= THIS IS YOUR PROBLEM LINE
   if (image_index >= 5) {
    // state = enemyState.FOLLOW;
   }
}
You will need to find a way to indicate that the first time the enemy is set to attack, then that is the only time that the image_index gets set to 0, probably outside of this script if the enemy only runs this script if it is in the attack state.
 
A

AwesomeAlvin

Guest
In your "else" section you are setting the image_index to 0 every time. It can't get off the first image in the spr_zombie_attack.
Code:
///scr_zombie_attack
var dis = point_distance(x,y, obj_player.x, obj_player.y);

if (dis > attackRange) {
   state = enemyState.FOLLOW;
} else {
   sprite_index = spr_zombie1_attack;
   speed = 0;
   image_speed = 0.16;
   image_index = 0;              <======= THIS IS YOUR PROBLEM LINE
   if (image_index >= 5) {
    // state = enemyState.FOLLOW;
   }
}
You will need to find a way to indicate that the first time the enemy is set to attack, then that is the only time that the image_index gets set to 0, probably outside of this script if the enemy only runs this script if it is in the attack state.
Hello, thank you for the response!

So this is the new code now:
Code:
var dis = point_distance(x,y, obj_player.x, obj_player.y);

if (dis > attackRange) {
    state = enemyState.FOLLOW;
} else {
    if (!attacked) {
        attacked = true;
        obj_player.hp -= 20; // Testing
        sprite_index = spr_zombie1_attack;
        image_speed = 0.16;
        image_index = 0;
    }
    speed = 0;
    if (image_index >= 5) {
        state = enemyState.FOLLOW;
        attacked = false;
    }
}
So now with this, the player hp goes down slowly, when it used to go down every frame.
If I comment out the "attacked = false", then the player hp will only go down once, and never again. So I think that the image_index is only called once now. However, the animation still isn't playing :(

EDIT: I found the problem. In my draw event, I had
Code:
draw_sprite_ext(sprite_index, 1, x,y,1,1, ang, c_white,1);
where the second argument (subimage) was at 1. So reading the draw_sprite_ext in the help doc, having it at -1 plays the concurrent animation. So when I had it at 1, it would just always stay on the first frame of the animation. So I solvied it by changing subimage to -1.

Thanks for the help on the first issue!
 
Last edited by a moderator:
Top