This project has moved. For the latest updates, please go here.

How to create explosion in FP 2.1.3

Topics: Developer Forum, User Forum
Aug 22, 2010 at 12:14 AM

Is there any example or someone who can help me how to create explosion.

I'm creating a game based on flash game "Crash the Castle", so I need this.

This game is for my final exam at collage.

Here's progress image :


So please help ! :)


Aug 22, 2010 at 7:57 AM

Your best bet would probably be to use Body.ApplyForce on every body within the radius of the explosion in the direction opposite it - most likely with some sort of falloff over the distance from the center of the explosion. That would look something like this:

foreach (Body body in myGameWorld.GetGameObjectsInRadius(explosion.Position, explosion.Radius))
   Vector2 vectorFromExplosion = body.Position - explosion.Position;
   // Note that here we're using a linear falloff. If you want the explosion force on this body to fall off more sharply with distance, you can use vectorFromExplosion.LengthSquared() instead.
   float explosionForce = (explosion.Radius - vectorFromExplosion.Length()) * explosion.Force;
   Vector2 forceOnBody = Vector2.Normalize(vectorFromExplosion);
   forceOnBody *= explosionForce;


As for animating the explosion, I'd suggest using an explosion generator like Explogen (try the first download link, for some reason the second one didn't work on my computer). A slightly less user-friendly alternative is Positech's Explosion Generator.