effects.clearParticles() doesn't clear particles?

I started a simple project for a two-player TRON-style light cycle game, and ran into an oddity where I can’t figure out how to stop a sprite effect.

It’s supposed to trigger an explosion when there’s a crash, and then clear the particles when starting the next round. However, the particles still stick around which looks odd:

Here’s the code:

        s1.startEffect(effects.fire, 500)
        pause(1000)
        reset()

function reset() {
    [...]
    bg.fillRect(0, 0, 160, 120, 0)
    bg.drawRect(0, 0, 160, 120, 1)
    effects.clearParticles(s1)
    effects.clearParticles(s2)
    if (game.currentScene().particleSources) {
        game.currentScene().particleSources.forEach(ps => ps.destroy())
    }
}

The particleSources loop was a brute-force attempt to get rid of leftover particles. Apparently the particles are distinct from particle sources - is there a clean way to get rid of them?

2 Likes

I’d have to look at the source to remember the exact justification behind it because we haven’t touched the particle effects in a while, but the effects.clearParticles clears the sources but lets the particles live out the rest of their lifespan so that it ‘looks nice’. particles.clearAll() does a full clear of all the particles on the screen for you

2 Likes

Thanks, particles.clearAll() works great for this purpose.

Do you think this would be helpful to add a note in the documentation at https://arcade.makecode.com/reference/effects/clear-particles ? Though I don’t know if there’s a way to call it from Blocks.

2 Likes

Hm probably yes, good point. Here’s that: https://github.com/microsoft/pxt-common-packages/pull/1358

2 Likes