Skip to content

Managing Particle Emitters

Syntax-Sculptor edited this page Nov 24, 2026 · 3 revisions

Playing and Stopping Particle Emitters

By default, Particle Emitters continuously emit particles while active, with the ParticleRate field determining how many particles are spawned each second.

Palette allows you to easily toggle continuous emission using the ParticleEmitter:Play() and ParticleEmitter:Stop() methods. Below is an example where the emitter stops continuously emitting particles after 5 seconds without destroying it. Keep in mind that calling Stop does not delete every particle on the screen.

local mod = RegisterMod("Palette Test", 1)
local Palette = include("palette_scripts.palette")

-- Equivalent to 5 seconds
-- Once this reaches 0, the Particle Emitter stops emitting particles.
local countdown = 30 * 5
local emitter

Palette:Init(mod)

mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
    -- Reset the countdown when entering a new room and creating a new Particle Emitter.
    countdown = 30 * 5

    local position = Game():GetRoom():GetCenterPos()

    emitter = Palette:CreateParticleEmitter("gfx/particle.png", position)
    emitter.StartSpeed = { Min = 6, Max = 12 }
    emitter.DirectionSpread = 25
    emitter.StartColor = { Min = KColor(0, 0.4, 0, 1), Max = KColor(0, 1, 0, 1) }
    emitter.StartScale = { Min = Vector(0.8, 0.8), Max = Vector(1, 1) }
end)

mod:AddCallback(ModCallbacks.MC_POST_UPDATE, function()
    countdown = countdown - 1

    -- Make sure an emitter was created and is not destroyed.
    if countdown == 0 and emitter and not emitter:IsDestroyed() then
        emitter:Stop()
    end
end)
2026-10-18.15-25-11.mp4

To re-enable continuous particle emission, call ParticleEmitter:Play().

You can use the ParticleEmitter:IsEmitting() method to check whether or not a Particle Emitter is continuously emitting particles.

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
print(emitter:IsEmitting()) -- true
emitter:Stop()
print(emitter:IsEmitting()) -- false
emitter:Play()
print(emitter:IsEmitting()) -- true

Manually Emitting Particles

Sometimes, you might want to manually emit particles. For example, you might want a particle effect that plays when the player takes damage. With Palette, you can call ParticleEmitter:Emit(count) to emit a set amount of particles. This works even if continuous emission is disabled:

local mod = RegisterMod("Palette Test", 1)
local Palette = include("palette_scripts.palette")
local emitter

Palette:Init(mod)

mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
    local position = Game():GetRoom():GetCenterPos()

    emitter = Palette:CreateParticleEmitter("gfx/particle.png", position)
    emitter.StartSpeed = { Min = 6, Max = 12 }
    emitter.DirectionSpread = 25
    emitter.StartColor = { Min = KColor(0, 0.4, 0, 1), Max = KColor(0, 1, 0, 1) }
    emitter.StartScale = { Min = Vector(0.8, 0.8), Max = Vector(1, 1) }
    -- Prevents continuous emission. `ParticleEmitter:Emit` will still work.
    emitter:Stop()
end)

mod:AddCallback(ModCallbacks.MC_POST_ENTITY_TAKE_DMG, function(_, player)
    -- Move the Particle Emitter to the player who got hurt.
    -- Make sure the emitter exists and was not destroyed to prevent errors.
    if emitter and not emitter:IsDestroyed() then
        emitter.Position = player.Position
        emitter:Emit(10)
    end
end, EntityType.ENTITY_PLAYER)
2026-10-18.15-27-38.mp4

Additionally, Emit() takes an optional second argument, which is a position offset Vector. For example, emitter:Emit(10, Vector(0, -20)) spawns 10 particles 20 pixels above the emitter.

Keep in mind that the number of particles that are spawned is capped by MaxParticles. If the cap is reached, additional particles won't spawn.

Warning

Calling ParticleEmitter:Emit() on a destroyed emitter will cause an error. If an emitter might have been destroyed, check ParticleEmitter:IsDestroyed() before calling Emit().

Clearing Particles

You can also delete every particle that the Particle Emitter had emitted using ParticleEmitter:Clear(). This does not destroy the Particle Emitter nor does it stop emission.

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
emitter:Emit(100) -- Emit 100 particles
emitter:Clear() -- ... And immediately destroy every single particle that belongs to the Particle Emitter.

To check whether the Particle Emitter is either continuously emitting particles or if at least one particle is still alive, you can use ParticleEmitter:IsPlaying():

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
print(emitter:IsPlaying()) -- true
emitter:Stop()
print(emitter:IsPlaying()) -- true if any particles were spawned from continuous emission, otherwise false.
emitter:Clear()
print(emitter:IsPlaying()) -- false
emitter:Play()
print(emitter:IsPlaying()) -- true

Destroying Particle Emitters

By default, Particle Emitters are destroyed when changing rooms/exiting the run, assuming PersistAcrossRooms is set to false. However, you can explicitly destroy a Particle Emitter, which clears its particles, permanently disables the emitter, and unregisters it from Palette.

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
emitter:Destroy()
print(emitter:IsDestroyed()) -- true

Pausing Particle Emitters

You can pause a Particle Emitter by calling ParticleEmitter:Pause(). While a Particle Emitter is paused, its particles will continue to render but the internal logic will no longer update. This means its particles will remain frozen on the screen.

You can use ParticleEmitter:IsPaused() to check if an emitter is paused. To unfreeze it, you can call ParticleEmitter:Resume().

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
emitter:Pause() -- Pauses playback
print(emitter:IsPaused()) -- true
emitter:Resume() -- Resumes playback
print(emitter:IsPaused()) -- false

Restarting Particle Emitters

You can restart a Particle Emitter by calling ParticleEmitter:Restart(). When restarting a Particle Emitter, it clears all of its particles and re-enables continuous emission. Keep in mind that it does not resume a paused emitter; you will still need to call ParticleEmitter:Resume() to resume it.

Following an Entity

Palette also allows you to have a Particle Emitter follow an entity. This can be really useful for a variety of effects, such as a trail that follows an entity or footstep particles. You can have a Particle Emitter follow an entity by calling ParticleEmitter:FollowEntity(player):

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
-- Assuming a player exists
local player = Isaac.GetPlayer()
emitter:FollowEntity(player)

The function also supports an optional second parameter which is a Vector that dictates the offset. For example, emitter:FollowEntity(player, Vector(0, 10)) will cause the emitter to follow 10 units below the player.

To have a Particle Emitter stop following an entity, you can call the function again but pass nil as the first argument:

-- Assuming it's already following an entity.
emitter:FollowEntity(nil)

To check if a Particle Emitter is following an entity, you can call ParticleEmitter:IsFollowingEntity(). Likewise, you can get the entity that the Particle Emitter is following by calling ParticleEmitter:GetFollowingEntity(), though it will return nil if it's following no entity.

Note

If an entity dies and a Particle Emitter is following it, it will continue to exist and emit particles. If you wish to have the Particle Emitter also be destroyed, you can check if ParticleEmitter:IsFollowingEntity() is false and then call ParticleEmitter:Destroy().

Prewarming

Let's say you want to have a Particle Emitter that looks like a fire. You could do something along the lines of this:

local mod = RegisterMod("Palette Test", 1)
local Palette = include("palette_scripts.palette")

Palette:Init(mod)

mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
    local position = Game():GetRoom():GetCenterPos()

    local flames = Palette:CreateParticleEmitter("gfx/particle.png", position)
    flames.MaxParticles = 150
    flames.ParticleRate = 60
    flames.Lifetime = { Min = 20, Max = 35 }
    flames.StartSpeed = { Min = 1, Max = 2 }
    flames.DirectionSpread = 20
    flames.StartScale = {
        Min = Vector(0.3, 0.3),
        Max = Vector(0.6, 0.6)
    }
    flames.StartColor = {
        Min = KColor(0.9, 0.2, 0.0, 0.6),
        Max = KColor(1.0, 0.7, 0.1, 0.9)
    }

    local embers = Palette:CreateParticleEmitter("gfx/particle.png", position)
    embers.MaxParticles = 60
    embers.ParticleRate = 12
    embers.Lifetime = { Min = 60, Max = 120 }
    embers.StartSpeed = { Min = 0.5, Max = 1.5 }
    embers.DirectionSpread = 45
    embers.StartScale = {
        Min = Vector(0.05, 0.05),
        Max = Vector(0.15, 0.15)
    }
    embers.StartColor = {
        Min = KColor(1.0, 0.5, 0.1, 0.8),
        Max = KColor(1.0, 0.9, 0.4, 1.0)
    }
end)
2026-11-22.11-01-35.mp4

It already looks passable. However, you'll notice that it takes around a second or two for the flames and embers to fully build up. There are various situations where you might not want your emitter to build up. Fortunately, this is where prewarming comes into play.

Prewarming lets a Particle Emitter instantly simulate a set number of frames, as if the emitter had already been running for that long. You can prewarm an emitter by calling ParticleEmitter:Prewarm(). By default, the number of frames it simulates corresponds to the emitter's Lifetime field. However, you can also pass an integer as an argument to override how many frames it simulates.

Let's apply prewarming to both of our emitters in the previous example:

mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
    local position = Game():GetRoom():GetCenterPos()

    local flames = Palette:CreateParticleEmitter("gfx/particle.png", position)
    flames.MaxParticles = 150
    flames.ParticleRate = 60
    flames.Lifetime = { Min = 20, Max = 35 }
    flames.StartSpeed = { Min = 1, Max = 2 }
    flames.DirectionSpread = 20
    flames.StartScale = {
        Min = Vector(0.3, 0.3),
        Max = Vector(0.6, 0.6)
    }
    flames.StartColor = {
        Min = KColor(0.9, 0.2, 0.0, 0.6),
        Max = KColor(1.0, 0.7, 0.1, 0.9)
    }
    flames:Prewarm(150)

    local embers = Palette:CreateParticleEmitter("gfx/particle.png", position)
    embers.MaxParticles = 60
    embers.ParticleRate = 12
    embers.Lifetime = { Min = 60, Max = 120 }
    embers.StartSpeed = { Min = 0.5, Max = 1.5 }
    embers.DirectionSpread = 45
    embers.StartScale = {
        Min = Vector(0.05, 0.05),
        Max = Vector(0.15, 0.15)
    }
    embers.StartColor = {
        Min = KColor(1.0, 0.5, 0.1, 0.8),
        Max = KColor(1.0, 0.9, 0.4, 1.0)
    }
    embers:Prewarm(150)
end)

We prewarm both of our emitters for 150 frames (or 5 seconds). Testing it in-game now:

2026-11-22.11-18-26.mp4

You'll now see that the flames and embers are already fully formed!

Warning

Be cautious with passing giant numbers! Passing a large number like 100,000 to embers:Prewarm can cause the game to briefly freeze.

Clone this wiki locally