Single-Point Particle Emitter
-
Introduction
Although you can use the prebuilt particle emitters, you can only achieve a few predefined visual effects. To unleash the full power of particle emitters, you need to learn to build and customize the particle emitter yourself.
Particle systems can be very complex, since we are dealing with many particles (small texture images) that are moving and changing at the same time.
For a simple start, we will look at the “single-point” particle emitter. This means all the particles are created at the same point, and they do not move away from this point.
Create the Single-Point Particle Emitter
To create a single-point particle emitter, you can use the following block, and specify “Point” as the shape.
Here is an explanation of the input parameters:
Shape
The shape here is not the shape of the particles, but rather the shape of the emitter that generates the particles. When we choose “Point” shape, all particles are created at the same initial position. We will discuss other shapes on other wiki pages.
Texture
The texture is the 2D image to be used as the particle. There are tons of textures you can select from the library.
Facing Camera
This input controls whether the particle images will be rotated to face the camera all the time. For example, as shown below, suppose the particle image is a 2D circle. If we make it always face the camera, then we will always see it as a full circle no matter how we rotate the camera; however, if we do not force it to face the camera, then we will see that it is always facing the up direction, and it becomes very thin when we look at it from the side.
Life Min/Max
These 2 numbers are the minimum and maximum lifetime of the particles. For each new particle that’s generated by the emitter, its lifetime will be a random number between these 2 values. For example, if the min life is 2 seconds and the max life is 4 seconds, then the actual lifetime of any one particle can be any value between 2 and 4 seconds. Suppose it is 3.5 seconds, then after 3.5 seconds, this particle will die (disappear).
Capacity
The capacity controls the maximum number of particles that will be created. It is also the maximum number of particles that can be displayed on the stage. Note that this may not be the actual number of particles displayed. It will still depend on the speed at which the particles are generated, which will be specified when we start the emitter. When we create the emitter, it will immediately create all the particles according to this capacity input, and then use them when the emitter fires, and reuse these particles after they die.
GPU
This input controls whether we will use the GPU of the computer system when it is available. The GPU is an extra processor besides the CPU of the computer, which enables the computer to draw the particles faster, and also enables some advanced variations of the particles. Usually you should set this to “Yes” to make use of the GPU when it is available.
Time Ratio
The time ratio controls how fast the particle animation is carried out. You can think of it as the speed of the clock for the particles relative to the real world. The higher this number, the faster the particles will move and change.
Name
The last input allows us to give the emitter a name, so that we can select it later.
The “Start Emitter” Block
After you have added an emitter to the scene, you can use the “start emitter” block to make the emitter spits out particles.
- Emitter Name: the first input is the name of the emitter. You can leave it blank if the emitter is the selected sprite object.
- Generation Method and Count: if “by rate”, then the emitter will keep firing out particles forever, and the third input will be the number of particles emitted per second. Note that if the “capacity” of the emitter is not large enough, you may not be able to emit particles at the given rate. If you choose “for one-time count”, then the emitter will only emit the given number of particles, then the emitter will stop until you start it again.
Example 1 - Repeatedly Firing One Particle
Here is probably the simplest program to create and fire a particle emitter:
The capacity is 1, so there is only one particle in the system that is repeatedly used. The lifetime of this particle is 1, and it is fired at a rate of 1, so this particle will be fired out, live for 1 second, then it will die, and then it is reused to fire again.
Example 2 - One Particle with a Longer Lifetime
Now suppose we change the lifetime to 3 seconds. Then each time the particle will live for 3 seconds. Even though the firing rate is set to 1, we still have to wait for 3 seconds before the particle dies, so that it can be reused to fire again.
Example 3 - More Particles with a Longer Lifetime
To keep firing at the expected rate of 1 per second, we have to increase the capacity of the emitter to at least 3.
This time, after firing the first particle, we wait one second, then try to fire again. We still have 2 unused particles, so we can afford to fire out the second particle, then we fire the third particle after another second. Therefore, we will see all 3 particles displayed, though they are at different stages of their lifetimes.
Example 4 - Higher Firing Rate
Now let’s increase the firing rate to 3 as well, so we can see up to 3 particles at a time. Note that since the firing rate is 3, the particles will be fired at a time interval of 1/3 seconds in the beginning.
After firing out all 3 particles, when we are ready to fire again, the 3 particles are still alive, so we hit our capacity limit again, and we have to wait until a particle to die to fire a new one out:
Starting and Ending Particle Size
The reason we are seeing the particle image expanding larger and larger is that each particle has a starting size and an ending size. By default, the particles start with a size of 1 and end with a size of 100.
You can change the starting and ending sizes using the following block:
The first input is the name of the emitter you are updating. You can leave it blank if the emitter is the current active sprite object.
The start size can be a range, such as between 10 to 20. For each particle, its starting size will be randomly chosen within this range.
The end size can be a range as well.
Lastly, you can specify the size range of the particle at an intermediate time point (between 0% and 100%). For example, you can specify that at 50% of the lifetime, the particle has to reach a size of 100. If the “progress” is set to -1, then the intermediate time point is disabled.
Note that if the “GPU” option is set to “yes”, then you will not be able to specify a range (the second number in each pair of size numbers will be ignored).
Example 5 - Fixed Sizes
If we set the starting size and the ending size to be the same, then the particle won’t be showing an animation of growing. Instead, they will stay at the same size throughout their lifetimes, and multiple particles will overlap with each other:
Example 6 - Randomly Changing Sizes
In this example, we specify a range for the starting and ending sizes:
As a result, the sizes of all 5 particles are different, and the gap between the rings is not evenly distributed.
Starting and Ending Colors
By default, all the particle images start as white, and end as black (transparent). You can set a starting color and an ending color for each particle using this block below. The color of each particle will gradually transit from the starting color to the ending color over the lifetime of the particle. Note that you can change the particle’s color even after it has started firing.
The first input is the name of the emitter you are updating. You can leave it blank if the emitter is the current active sprite object.
The starting color can be a range defined by 2 colors (only 1 color is used when the particle is “GPU” type). For each particle, its starting size will be randomly chosen within this range.
The ending color can be a range defined by another 2 colors as well.
Lastly, you can specify the color range of the particle at an intermediate time point (between 0% and 100%). For example, you can specify that at 50% of the lifetime, the particle has to change to a particular color range. If the “progress” is set to -1, then the intermediate time point is disabled.
Example 7 - Set a Random Starting Color
We can use 2 different colors (red and green) for the starting color range, and set the ending colors to be pure black. We will see that the particles take on a random color between red and green.
We can see some particles are orange and yellow:
Example 8 - Set Both Starting and Ending Colors
If the ending color is not black, then the particles will show that color when it dies.
Notice that at the edge of the circle, the particle becomes blue before it suddenly disappears. This is why we usually set the ending color to black, so that the particles become almost transparent before they die, which will look much more smooth.
Initial Rotation
By default, all particles are created with no initial rotation, so they look the same. We can specify the initial rotation angle for the particles as well, using the following block:
The first input is still the name of the emitter.The second and third parameters allow us to specify a range of angles. If we set the range to be between 0 degrees and 360 degrees, then the initial angle of the particle can be any value around the circle.
Example 9 - Random Initial Rotation Angles
In this example, we use a different texture of “magic 03” from the “Kenny” category.
This texture makes it easier to see the different angles:
This is the result: -