Finally: a Particle System!

Daniel Sperl on June 4, 2011

Hi folks,

I know it has been a long time coming, but I finally took the time and created a particle system for Sparrow. W00t! This is a feature that has been requested since day one, but there were always more pressing things on my TODO-list, delaying this more and more.

"Sample Particle Systems"

Furthermore, I was never quite sure if the particle system should become part of the Sparrow core code. Granted, many games use particle systems, but by far not all of them. And even then, there are lots of different particle systems for different use-cases. Creating a class that meets all those demands is nearly impossible, and would result in a huge and complex piece of code being added to the core.

With the completion of Sparrow’s extension system, however, the decision was settled. I created the particle system as an extension that can be grabbed by anybody who needs it. It goes without saying that we will support and update this extension just as if it was a part of Sparrow’s core code.

Particle Designer

Screenshot of the Particle Designer

As I said, a particle system is a complex beast. It has to be flexible enough to be used for anything from the slow decline of snowflakes to the mighty impact of an explosion. In other words: there are a lot of parameters that need to be configured.

That’s why I decided to use Particle Designer as the main input for the particle system. That is a great tool which allows you to configure a plethora of different settings and view the results in real time. Sparrow can load configuration files from the Particle Designer directly. The tool is not free, but it’s definitely worth its money (just like, err, Sparrow).

That does not mean that you have to use this program, though. You can tween the settings directly in the XML file as well, of course. But due to the sheer amount of settings, this becomes cumbersome quickly.

Code samples

The code below shows you how to create a particle system in Sparrow. The class SXParticleSystem is a subclass of SPDisplayObject and behaves as such. You can add it as a child to the stage or to any other container. As usual, you have to add it to a juggler (or call its advanceTime: method once per frame) to animate it.

// create particle system
SXParticleSystem *ps = [[SXParticleSystem alloc] 
ps.x = 160.0f;
ps.y = 240.0f;
// add it to the stage and the juggler
[self addChild:ps];
[self.juggler addObject:ps];
[ps release];
// start emitting particles
[ps start];

// stop emitting particles
[ps stop];

Doesn’t look too difficult, right? Since SXParticleSystem is a first class member of Sparrow’s display tree architecture, you should already be familiar with how to use it. You just have to call the start and stop-methods to control it. The rest of the work is done in the Particle Designer.

You can find the particle system on its dedicated page in the Sparrow Wiki. I hope you like it! Don’t forget to post your feedback below.