As we've seen before, templates are powerful tools, but sometimes you might want more control over the effects you create than what the library offers pre-made. This chapter will break down how a template is built, and how you can use that knowledge to create your own effects using emitters, variations and modules.
To understand how custom effects work, let's break down the confetti template we saw before. Note that some parts are omitted for the sake of brevity.
Let's break down the effect bit by bit. First, we provide fill in values that the user potentially omitted, to ensure that all the configuration we need has a proper value. For now, let's just focus on the modules.
Modules allow particle to change their appearance over their lifetime. How they work is best explained on their own documentation page, but here we are simply creating a new module function that drives the size of the particles over their lifetime.
After we've prepared all the options we need, it's time to finally create the
Emitter object. This is the instance that will ultimately be responsible for spawning our confetti-particles.
We use the fact that we can pass every configuration option that we need directly into the method that creates a new emitter in the scene.
Note that we're passing variations to some of the options. This is to - as the name might suggest - allow variety in the way that particles are emitted. You can learn more about variations on their documentation page.
The emitter options control what properties the emitted particle are given after they are spawned, things like color, velocity or rotation.
The emission options control the speed at which particles are emitted. The
rate option specifies how many particles should be emitted per second, while the
bursts option can be used to specify points in time at which groups of particles should be spawned. For the confetti effect, we only want particles to be emitted all at once, so this is fitting.
The shape options specify the area that particles are emitted from, and the direction that they are emitted in. The source is defined by a rectangle.
The renderer options define the way that particles appear on the screen, and how certain properties of them are applied to their looks, for example the lighting and transform.
That's all there is to it! If you want to learn more about how to create custom effects, you can check out the other guides.
With the knowledge we just gained from learning how custom effects work, we can create more effects, such as the hearts effect seen in the demo.