Particle System
Perhaps your game needs effects like burning fire, spell casting visuals or explosions. How would you make such complex effects? Is it even possible? Yes, it is. Using a particle system. The term particle system refers to a computer graphics technique that uses a large number of very small sprites or other graphic objects to simulate certain kinds of fuzzy phenomena, which are otherwise very hard to reproduce with conventional rendering techniques. Some realistic examples might include highly chaotic systems, natural phenomena, or processes caused by chemical reactions. Here are a few examples of particle effects:
Tools for creating Particle Effects
Even though you can always create particle effects by hand, massaging each property to your liking. There are several third party tools for creating particle effects. A few of these tools are:
- Effekseer: Effekseer is a tool editing particle effects.
- Particle Designer: A very powerful particle effects editor on Mac.
- V-play particle editor: A cross-platform particle editor for Cocos2d-x.
- Particle2dx: An online web particle designer.
These tools usually export a .plist
file that you can read in with Cocos2d-x to use your creation inside your game. Just like with all of the other classes we have worked with so far we use the create()
method:
// create by plist file
auto particleSystem = ParticleSystem::create("SpinningPeas.plist");
Built-In Particle Effects
Are you ready to add particle effects to your game? We hope so! Are you not yet comfortable with creating custom particle effects? For ease of convenience there are a number of built-in particle effects that you can choose from. Take a look at this list:
-ParticleFire: Point particle system. Uses Gravity mode.
-ParticleFireworks: Point particle system. Uses Gravity mode.
-ParticleSun: Point particle system. Uses Gravity mode.
-ParticleGalaxy: Point particle system. Uses Gravity mode.
-ParticleFlower: Point particle system. Uses Gravity mode.
-ParticleMeteor: Point particle system. Uses Gravity mode.
-ParticleSpiral: Point particle system. Uses Gravity mode.
-ParticleExplosion: Point particle system. Uses Gravity mode.
-ParticleSmoke: Point particle system. Uses Gravity mode.
-ParticleSnow: Point particle system. Uses Gravity mode.
-ParticleRain: Point particle system. Uses Gravity mode.
Using ParticleFireworks
as an example, you can use the built-in effects easily:
auto emitter = ParticleFireworks::create();
addChild(emitter, 10);
The result is a particle effect that looks something like:
But what do you do if your particle effect isn't quite the way you want? That's right, you can manually manipulate it! Let's take the same fireworks example above and manipulate it even further by manually changing its properties:
auto emitter = ParticleFireworks::create();
// set the duration
emitter->setDuration(ParticleSystem::DURATION_INFINITY);
// radius mode
emitter->setEmitterMode(ParticleSystem::Mode::RADIUS);
// radius mode: 100 pixels from center
emitter->setStartRadius(100);
emitter->setStartRadiusVar(0);
emitter->setEndRadius(ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS);
emitter->setEndRadiusVar(0); // not used when start == end
addChild(emitter, 10);