Featured iPhone Development Resources

Source Code: Particle Based Explosions In iPhone OpenGL ES

Hi everybody, if you’ve been following me on twitter you may have seen my tweet about an open sourced iPhone version of Space Invaders

If you haven’t seen it yet, it’s a very concise implementation of the classic game, and also a very basic implementation, but I noticed something pretty cool while playing with it, and that was the particle based explosions. So what I did was spend about 3 minutes playing with the code, and I came up with the demo shown here in this video.

To create these explosions a Particle Emitter created by the guys at 71 Squared (makers of some great iPhone game development tutorials) along with a custom texture class. 

To create the explosions a Particle Emitter is first created and initialized using the initParticleWithEmitter class, where you can specify parameters for the color, duration, size, number of particles, and gravity of the resulting display of particles (an example of this is in the EaglView.m file).

To display the particles a time index is created, and the update: method is executed along with the renderparticles method.  I won’t go into the details here as the ParticleEmitter classes are extremely well documented.

Download the source code for the explosion generator here:
>>> Explosion Generator Source <<<

Have fun with the code.


7 replies on “Source Code: Particle Based Explosions In iPhone OpenGL ES”

Hi thanks for this, its exactly what I needed. I've tried to incoporate the particle emitter into my project and the points are just coming out as squares, its like they are ignoring the texture. All of my other elements are drawing ok, so I'm wondering if its a combination of my view setup and the VBO's (which I've never used before). From my bad description does anything jump out at you at what I could be doing wrong?


I got it working in the end, think is was my texture settings, but now I get a weird effect that some of the particles appear in the top left of the screen (phone is landscape, button to the right) and very large, I keep thinking that maybe its some data not being cleared down properly as it only happens on the phone and not in the simulator ๐Ÿ™

OK, just in case anyone else hits this problem, turns out it was a value I was passing to the emitter, I set the particleSize to 5.0f and the effect occurs.

Still a great particle emitter though ๐Ÿ™‚

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.