Explosion (Game Maker)

Explosions are generally just another object with a sprite that looks like an explosion. Explosions are usually created when an object is destroyed. It's important to make sure that the sprite origin is at the center of the sprite for both objects, this way you can just create the explosion at the same location of the object that is destroyed.

//In the Destroy Event
instance_create(x,y,obj_explosion);

If the sprite origin for the exploding object is not in the center, but rather in the top/left corner, you can find the center using this code :

xexplode = x + sprite_width / 2;
yexplode = y + sprite_height / 2;
instance_create(xexplode,yexplode,obj_explosion);

If you want other objects to be destroyed by the explosion, just set a Collision event with the explosion in the object you want to destroy.

If you put the explosion sound in the Create event of the explosion, it will automatically play the sound when it is created, freeing you from having to play the sound in the destroy events of individual objects using that explosion.

To make sure that the explosion only goes through its subimages once, be sure to destroy it its Animation end event

Related Pages

Tutorials

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.