ParticleSystem

author:
Daniel Sperl
description:
Particle System for special effects
lastupdate:
2012-08-20
compatible:
v1.0+
tag:
particles, effects, 71squared
homepage:
https://github.com/Gamua/Starling-Extension-Particle-System
download:
https://github.com/Gamua/Starling-Extension-Particle-System/archive/master.zip

Overview

The Adobe Flash Plugin is needed to display this content.

This class provides an easy way to display particle systems.

Particle Systems can be used to create special effects like explosions, smoke, snow, fire, etc. To provide that flexibility, it can be configured with numerous settings that control particle movement, size, color, etc.

Finding the perfect settings for your effect is not easy. For that reason, there are tools that allow you to modify the settings and preview the resulting particle system in real time.

  • Particle Designer, the original from 71squared. It's a great tool that contains access to a large online library of free emitters. Warmly recommended for any OS X user!
  • Particle Editor is a free online tool built with Starling. It lacks the online emitter library, but allows editing and previewing directly within the browser. (More info here.)

Particle Designer from 71squared

Sample Project

The demo-directory contains a sample project with four sample configurations. Switch between configurations in Demo.as by hitting the space key.

The following sample configurations are provided:

  • drugs.pex
  • fire.pex
  • sun.pex
  • jellyfish.pex

Usage

The extension contains two Particle System classes:

  • “ParticleSystem.as”: A generic particle system. Use this as a base class if you want to create a custom Particle System (for advanced users).
  • “PDParticleSystem.as”: This is likely what you want to use: a particle system that can be configured using the editors described above. ('PD' stands for 'Particle Designer'.)
// embed configuration XML
[Embed(source="fire.pex", mimeType="application/octet-stream")]
private static const FireConfig:Class;
 
// embed particle texture
[Embed(source = "fire_particle.png")]
private static const FireParticle:Class;
 
// instantiate embedded objects
var psConfig:XML = XML(new FireConfig());
var psTexture:Texture = Texture.fromBitmap(new FireParticle());
 
// create particle system
var ps:PDParticleSystem = new PDParticleSystem(psConfig, psTexture);
ps.x = 160;
ps.y = 240;
 
// add it to the stage and the juggler
addChild(ps);
Starling.juggler.add(ps);
 
// change position where particles are emitted
ps.emitterX = 20;
ps.emitterY = 40;
 
// start emitting particles
ps.start();
 
// emit particles for two seconds, then stop
ps.start(2.0);
 
// stop emitting particles; the existing particles will continue to animate.
ps.stop();
 
// stop emitting particles; the existing particles will be removed.
ps.stop(true);

Remarks

Not touchable

The particle system's bounds are always a zero-sized rectangle, because calculating the real bounds would be very time-consuming. That means that you can't touch a particle system.

Particle Designer: emitter location ignored

The emitter location you can set in the Particle Designer is ignored, too. To move the particle system around, change the x- and y-properties of the particle system, or the emitterX- and emitterY-properties at run-time. (While the former moves the complete coordinate system around, the latter just changes where new particles appear.)

Particle Designer: systems are upside-down

Furthermore, the movement of particles is upside-down in Starling, compared to the Particle Designer. That's because Starling uses another coordinate system (with the origin at the top left). To work around that, you can either set the “scaleY” property of the particle system to “-1”, or design the particle system upside down.

Need more options?

The Starling user Michael Trenkler created an advanced version of this particle system class, which adds tons of additional features. So if you're looking for more control over you particle systems, definitely have a look at his Improved Particle System!

Changelog

  • 2011/09/02: First public version
  • 2012/01/03: Dispatching Event.COMPLETE
  • 2012/02/08: added properties for all settings
  • 2012/02/27: compatibility with Starling 1.0
  • 2012/04/05: Fixed color overflow error (output was different than PD preview)
  • 2012/04/28: Added support for rotated particles
  • 2012/05/13: fixed massive mem-leak caused by strange Flash Player phenomenon
  • 2012/07/18: added support for the drawCount statistic
  • 2012/10/25: added 'pause' method, made texture property writable
  • 2012/11/06: added support for ATF textures
  • 2013/08/05: fixed that particles initialized with a zero lifetime were being displayed
  • 2013/08/20: compatibility with Starling 1.4
  • 2013/10/02: added 'smoothing' property

Source Code

You can browse the source code of the particle system on its GitHub page.

User Comments

Feel free to edit this part of the page!

Where oh where has the “pause” method gone? People need the ability to pause their games. bring it back please….

  extensions/particlesystem.txt · Last modified: 2014/07/31 08:43 by daniel
 
Powered by DokuWiki