Today’s guest tutorial comes to you courtesy of Corona Ambassador and Portland, Oregon app developer Ed Maurina. Ed is a regular contributor to the weekly Corona Geek hangouts and an active member of the Corona Community. He has developed games for REEL FX Studios, maintains his Corona SSK game development library, and recently created a particle editor that runs in the Corona Simulator. In this tutorial, he explains how to design basic particle emitters. Check out his work and blog at RoamingGamer.com.


In my last article, Corona Particle Tools and Data Formats, we talked about the choices available to you for authoring, loading, and creating particle emitters. In this article, you will learn how to make three different particle emitters.

campfire waterfall explosion
campfire waterfall explosion

These three emitters are a good starting point for unraveling the mysteries behind emitter creation and they should give you a pain-free introduction to making your own.

Particle Editor for Corona SDK

Throughout this article, we will be using the Particle Editor for Corona SDK (Roaming Gamer, LLC.). This runs directly in the Simulator for the most accurate results within Corona SDK. You may use another tool to create emitters, but the parameter names (as shown below and in the videos) may be slightly different in the other tools. Regardless of your choice, I believe you’ll discover that making emitters is both fun and easy!


Campfire

One trick to making an emitter for your app is to start with an emitter that’s visually close to what you want. Fortunately, Particle Editor comes with 11 starter emitters and the ability to import additional emitters. So, making new emitters is often as easy as cloning an existing one and tweaking it a bit.

Now, please watch this video, where I’ll quickly show you how to convert starter emitter #2 (the candle emitter) into a passable campfire emitter.

Once you’ve watched the video, please start the authoring tool of your choice and try using the settings below to approximate the results shown in the video.

Emitter Settings — Basic
Parameter(s) Value
Max Particles ~200
Duration -1
X Variance 75
Y Variance 0
Angle 270
Angle Variance ~25
Emitter Type Gravity
Emitter Settings — Gravity
Parameter(s) Value
X Gravity 0
Y Gravity 0
Speed 80
Speed Variance 30
[remaining settings] 0
Particle Settings
Parameter(s) Value
Lifespan ~0.25
Lifespan Variance ~2.0
Start Size ~45
Start Size Variance ~10
End Size ~60
[remaining settings] 0
Color Settings

In the video, I decided to stay with the default colors from emitter #2. However, you might want to experiment with these settings a bit. I only suggest that you keep the variances at zero to begin with. Changing them early can complicate editing significantly.

Blend/Alpha Settings
Parameter(s) Value
Start Alpha 0.2
Finish Alpha 0.1
Source Blending Source-Alpha
Destination Blending One

Tips & Tricks

Although making a campfire or other flame-based effect is pretty straightforward, here are some useful tricks:

Non-Accelerating Flame

One thing you want to avoid is an accelerating flame. That is, you don’t want the flame particles to speed up as they rise. So, for this effect, you should zero out the gravity settings and use speed settings alone to achieve the rising flame.

Fading Alpha

Another trick is to use a Start Alpha that is higher than Finish Alpha. Why? If you consider it, a flame should start off somewhat opaque and gradually disappear.

Variable Lifespans

The final trick has to do with particle Lifespan. It may seem counter-intuitive, but the flame particles will look best with a short base lifespan and large (~8x the base) variance.


Waterfall

Once you’ve made a campfire emitter, you’ll discover that by simply making a few tweaks, you can easily convert it into a waterfall.

In the video below, I’ll take the campfire emitter we just finished and convert it to a waterfall.

Once you’ve watched the video, please start the authoring tool of your choice and try using the settings below to approximate the results shown in the video.

Emitter Settings — Basic
Parameter(s) Value
Max Particles ~300
Angle 360
Angle Variance 0
Emitter Settings — Gravity
Parameter(s) Value
Y Gravity 100
Speed 0
Speed Variance 0
Particle Settings
Parameter(s) Value
Lifespan ~2.0 (greater = taller waterfall)
Lifespan Variance 0
Color Settings
Parameter(s) Value
Start Red 0.75
Start Green 0.65
Start Blue 0.9
Finish Red 1
Finish Green 1
Finish Blue 0.75
[other variances] 0
Blend/Alpha Settings
Parameter(s) Value
Start Alpha 0.1
Finish Alpha 0.2

Tips & Tricks

You’ll notice that it was easy to change a campfire into a waterfall, but the changes I made were the opposite of those I stressed for the fire.

Accelerating Water

Unlike a flame, water should accelerate as it falls, so you should set the speed settings to zero and use a positive gravity instead. More gravity equals a taller waterfall.

Increasing Alpha

For a waterfall, we want to simulate an accumulation of mist and water droplets. We can do this by starting the particles with a low alpha and increasing it by about 2×. However, if you choose this approach, you should probably create and use a second emitter that simulates splashing at the bottom of the waterfall. Also, if the water is supposed to fully vaporize, then keep the campfire settings.


Explosion

In this final example, we’ll make an emitter that simulates an explosive burst. That is, the particles radiate in all directions from the center of the explosion. Please watch the following video to see how this is achieved:

Once you have watched the video, please start the authoring tool of your choice and try using the settings below to approximate the results shown in the video.

Emitter Settings — Basic
Parameter(s) Value
Max Particles ~200
Duration 0.25
X Variance 0
Y Variance 0
Angle 360
Angle Variance 360
Emitter Type Gravity
Emitter Settings — Gravity
Parameter(s) Value
X Gravity 0
Y Gravity 0
Speed 115
Speed Variance 60
[remaining settings] 0
Particle Settings
Parameter(s) Value
Lifespan ~0.05
Lifespan Variance ~0.5
Start Size ~10
Start Size Variance 0
End Size ~65
[remaining settings] 0
Color Settings
Parameter(s) Value
Start Red 0.85
Start Green 0.85
Start Blue 0
Finish Red 1
Finish Green 0
Finish Blue 0
[other variances] 0
Blend/Alpha Settings
Parameter(s) Value
Start Alpha 0.5
Start Alpha Variance 0.5
Finish Alpha 0.2
Finish Alpha Variance 0
Source Blending Source-Alpha
Destination Blending One

Tips & Tricks

Here are some tips pertaining to the explosion emitter:

Finite Duration

An explosion (emitter) should only play for a short period of time and then it should stop producing particles. To achieve this, we set the duration of the emitter to 1⁄4 of a second.

360-Degree Emission

A burst explosion should radiate particles in all directions around the center of the exploding object. To achieve this effect, we simply set the emitter’s angle to exactly 360 degrees with no variance.

Explosion Size

The most difficult part of the explosion to tune is the size. This is partly controlled by the emitter duration, but the rest of this is controlled by modifying the ejection speed and particle lifetimes. I suggest starting with the settings below and then tweaking each of these parameters individually to
see the effect:

  • Emitter Settings — Basic → Duration
  • Emitter Settings — Gravity → Speed
  • Emitter Settings — Gravity → Speed Variance
  • Particle Settings → Lifespan
  • Particle Settings → Lifespan Variance
Color

Finally, you’ll want to experiment with the coloration. In this example, I created a fairly standard yellow/red explosion, but if you’re making a sci-fi game, you may want to experiment with blue, green, and other variations.


In Summary

For your convenience, the samples outlined above are available for download here. Hopefully this tutorial, and the previous tutorial on Corona Particle Tools and Data Formats, has been useful in the exploration of the various tools and methods used alongside Corona’s display.newEmitter() API and its related functions. Questions or comments? Please leave your feedback below.

  1. Thanks for the great post.
    Specifically for Camp fire, another ridiculously easier and free alternative done in less than 10 lines of code –

    local function fire()
    local beam = {}

    for i = 1, 20 do

    –Have used circle, but if you use a blurry yellow glow, it would look more like a fire

    beam[i] = display.newCircle(0,0,3.5) –display.newImage(“glow4.png”)–

    beam[i].x, beam[i].y = math.random(100,200) , 500
    beam[i].alpha = 0.5
    beam[i].trans = transition.to(beam[i], { x = math.random(100,200), y = math.random (300, 400), alpha = 0.1, time = math.random(1000, 1200), delay = 100, onComplete = function() if beam[i] then beam[i]:removeSelf() end end })
    end
    end
    timer.performWithDelay(200, fire, -1)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>