Physics Explosion

4

Attached Files

The following files have been attached to this tutorial:

.capx

explosiontutorial.capx

Download now 56.76 KB

Stats

5,368 visits, 7,598 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 7 Jun, 2013. Last updated 19 Feb, 2019

Physics Explosion

I've been looking for a tutorial that explains how to make a explosion, but I can't find any. So I figured I would make one myself. A physics explosion can be very cool in many games. I hope you will enjoy making it with me.

Setting up the objects

To make a physics explosion you of course need some "physic-objects".

We will use four different objects in this tutorial. One "box", one "ground", one "tnt" and one "mouse".

If you don't have any images yourself you can take these (that I made).

The box.

The tnt.

The ground.

Let's start setting it up!

Insert a new object and make it a sprite that's called "box". Load in your image or the box image above. Click "add new behavior" and choose physics. You don't need to change any of the physics properties.

Insert a new object and make it a sprite that's called "tnt". Load in your image or the tnt image above. Also add a new animation called "explode". Make this a explosion. You can use the image underneath, or just paint a simple image yourself, with a bit orange and red and stuff. IMPORTANT! Add a new frame after the explosion picture that is just empty. Then you may want to raise the frame rate to about 20. Click "add new behavior" and choose physics. You don't need to change any of the physics properties.

Insert a new object and make it a tiled background that's called "ground". Load in your image or the ground image above. Click "add new behavior" and choose physics. IMPORTANT! For this one you will actually have to change one of the properties. Change "immovable" from No to Yes.

Insert a new object and make it "mouse".

Now when you got all your objects imported you can move them around and build a nice test scene that looks about like this:

The event

Go to your event sheet and add a new event. Make it: mouse>onObjectClicked>tnt.

Then click add action. Make it: box>applyImpulseAtAngle

Set the Impulse to about 10 (you can set it to whatever you want but I recommend that you set it to about 10). Then set the angle to: angle(tnt.X, tnt.Y, box.X, box.Y) + random(15)

(you can just copy and paste that).

The random thing isn't needed, but it just adds that "little extra touch" if you get what I mean, It just looks a bit more realistic.

Now you're done with the most hard part.

Add another action and make it: tnt>setAnimation>explode.

Add another action and make it: system>wait>0.1

Add another action and make it: tnt>destroy.

You're done!

Now, why not try it out? Click on the tnts to explode them. You can play around and make more tnts and bigger scenes, or more boxes, well you can do whatever you want.

I hope you enjoyed reading this tutorial and I hope everything worked out the way it should. This is my first tutorial EVER so why don't you leave a comment and tell me what you think?

//Totte

.CAPX

explosiontutorial.capx

Download now 56.76 KB
  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!