animation before instance_destroy (help)

kureoni

Member
i have this code for the enemy IA but when it dies the instance is destroyed without running the animation before
how do i change that?

GML:
mp_potential_step(obj_player.x, obj_player.y, spd, obj_colision)

if (life <= 0){
    sprite_index=spr_enemy1_death
    instance_destroy()
}
 

AnotherHero

Member
You're having the sprite_index change the same frame you destroy the instance.

You need to do an image_index check! Like
GML:
if (image_index > image_number) {
    instance_destroy();
}
 

DPMlofty

Member
Hey, you can do something like this
GML:
if(life <= 0){
    sprite_index = spr_enemy1_death;
    if(image_index >= "maximun numbers of frames of the death sprite"){
        instance_destroy();   
    }
}
 

kureoni

Member
You're having the sprite_index change the same frame you destroy the instance.

You need to do an image_index check! Like
GML:
if (image_index > image_number) {
    instance_destroy();
}
it runs the animation on a loop and it does not destroy the instance
some instances keep following the player, some stop etc
 
Top