Windows SOLVED // how do I respawn an object on the place it got destroyed?

A

anjai

Guest
I tried to find it out myself but all of the tutorials explain how to randomly respawn after some time and I need my object to respawn on the exact same place it got destroyed and just after it got destroyed and not at a certain amount of time :) If someone could tell me how to do it or where to find the information I would be incredibly thankful!

I made a begin step event on the object which I need to respawn and added this code:

Code:
if (hp <= 0)
{
instance_destroy();
}
I also made a collision event on the bullet:

Code:
with (other)
{
hp = hp -1;
}

instance_destroy();
 
Last edited by a moderator:

Rob

Member
There are a couple of ways you can do it.

One way is to use the "Destroy" event of the object from which you want to spawn another one.

In the destroy event (or the same block where the instance's hp <= 0 will also do):


GML:
//Destroy event of object that you want to spawn another object
var new_object = instance_create_layer(x, y, layer, obj_to_be_spawned);

with new_object{
    //You can set up some individual variables for this new instance if you need to here
}
 

ThraxxMedia

Member
An alternative approach would be to change the instance (using instance_change) instead of destroying it. As an example, imagine having a frozen enemy, and by shooting at it you'd shatter the ice. The unfrozen enemy object will then replace the previous one in the exact same spot without having to provide any coordinates.

GML:
if (hp <= 0)
{
    // Play your death animation, e.g. creating a puff of smoke or some particles
    
    instance_change(obj_unfrozen_enemy, true);
}
 
Top