instance_destroy once Sprite changes?

W

Warren Long

Guest
Hi All,

My bullets destory when they hit my enemy object, when the object dies and changes to death sprite... it's obviously same object so bullets still destroy hitting it.

How can I make the bullets stop instance_destroy once the monster changes to death sprite and is dead?

Is the only way making a new objec for dead sprite?
 

jo-thijs

Member
So, you let the bullet destroy itself in its collision event with an enemy object?
Then change that to:
if other.sprite_index != spr_enemy_dead
instance_destroy();
 
W

Warren Long

Guest
I'm trying to set it so at least 2x death sprites dont destroy instance.

I've used your advise above-

if (other.sprite_index != spr_alien1_dead) {
instance_destroy();

Which works a treat, but when I try this with another object (enemy), it wont work at all.. bullets just destroy. Any suggestions?


if (other.sprite_index != (spr_slug_dead) || (spr_slug_eat)) {
instance_destroy();
}
 
W

Warren Long

Guest
Just a loser, tried everything but just got answer after posting the above.

This fixed it-

if (other.sprite_index != spr_slug_dead && other.sprite_index != spr_slug_eat) {
instance_destroy();
}
 

jo-thijs

Member
Oh yeah, the || is a binary operator that operates on numbers,
convert them to integers by some rounding mechanism
and then checks if either of the 2 are strictly positive.
If so, a || b will return 1 and it will return 0 otherwise.

This:
Code:
other.sprite_index != (spr_slug_dead) || (spr_slug_eat)
is equivalent to:
Code:
(other.sprite_index != spr_slug_dead) || (spr_slug_eat)
and if spr_slug_eat is not the first sprite in the resource tree, this is equivalent to:
Code:
true
 
D

DekuNut

Guest
Why not create a parent enemy object, and give it a dead variable. When an enemy is killed, set its 'dead' variable to true, then all you have to do is reference the parent object to check whether your children objects have set to true.

example - collision event with obj_enemy_parent
if (!dead) {
other.dead = true; //use other to reference the colliding object id (ie. the enemy object).
instance_destroy();
}

with this, the bullet will check the parent object, which will act as a reference point to all children objects. Then this will set the object the bullet collided with (ID obtained through 'other') and set its variable 'dead' which it inherited from the parent object 'obj_enemy_parent'
 
Top