Skip to content

19 Particle Effect

In this chapter, we will add a particle effect to Note.

Define the Particle Effect

Particle effects are short visual animations spawned by the engine. Open guide/lib/particle.py and replace its placeholder Particles class with this standard particle:

python
from sonolus.script.particle import StandardParticle, particles


@particles
class Particles:
    note: StandardParticle.NOTE_CIRCULAR_TAP_CYAN

Spawn the Effect on a Hit

In Note.touch in guide/play/note.py, add the following code after the sound-effect match from chapter 18 and before self.despawn = True. It spawns an effect twice the size of the Note for 0.3 seconds, without looping:

python
from guide.lib.particle import Particles


class Note(PlayArchetype):
    # ...

    def touch(self):
        # ...

        for touch in touches():
            # ...

            layout = Rect.from_center(
                Vec2(0, 1),
                Vec2(4 * Config.note_radius, -4 * Config.note_radius),
            )

            Particles.note.spawn(layout, duration=0.3, loop=False)

            # ...

    # ...

Checkpoint

Run the level and hit a Note. A cyan circular particle effect should appear around the Note position for 0.3 seconds.