All examples · Sprites and 2D

Particles written in code

What this example shows

createParticles({ effect }) takes the effect itself, written in code with the same fields as a .particles file. It is ready at once and can depend on the game.

Here the dust behind the car is the colour of the ground it drives on: each stage builds its effect from its palette, with lerpColor for the colour it fades into, and the puff it shows is painted with createPixelTexture. Click to drive to the next stage.

There is one emitter per stage and only the current one is lit, so the old dust settles on its own while the new one starts. Handing the same object to several emitters makes them share one effect, as if they named the same file.

Starting