Skip to content

Animating Particles #2 ‐ ColorOverLifetime

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

Introduction

So far, we've learned how to animate a particle's angular velocity using the RotationOverLifetime module and a particle's size using the ScaleOverLifetime module. On this page, we're going to learn how to have particles change color over their lifetime. It's quite similar to our lifetime modules, though there are some differences.

ColorOverLifetime

Similarly to our previous modules, you can access and enable ColorOverLifetime like so:

local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
emitter.ColorOverLifetime.Enabled = true

Unlike the modules we've learned so far, ColorOverLifetime needs to animate color and transparency independently. Because of this, Keys, KeysMin, and KeysMax do not exist for ColorOverLifetime. Instead, they're replaced by these fields:

  • Gradient
  • GradientMin
  • GradientMax

All three of these fields hold a Gradient object, which simply stores two different tables of keyframes:

  • ColorKeys: A list of KColor keyframes that controls the particle's color over its lifetime. The Alpha field is ignored.
  • AlphaKeys: A list of number keyframes that controls the particle's transparency over its lifetime.

In Lua, the structure of a Gradient object is like this:

-- You should already know how keyframes work from the previous page. If not, reread it.
{
    AlphaKeys = {
        { Time = 0, Value = 1 },
        { Time = 1, Value = 1 },
    },
    ColorKeys = {
        { Time = 0, Value = KColor(1, 1, 1, 1) },
        { Time = 1, Value = KColor(1, 1, 1, 1) }
    }
}

With that explained, below is a snippet that causes particles to quickly fade in when appearing, before quickly fading out at the very end. On top of it, the color gradually shifts from red to orange throughout their lifetime.

-- In MC_POST_NEW_ROOM
local position = Game():GetRoom():GetCenterPos()

local emitter = Palette:CreateParticleEmitter("gfx/particle.png", position)
emitter.ColorOverLifetime.Enabled = true
emitter.DirectionSpread = 30

emitter.ColorOverLifetime.Gradient = {
    AlphaKeys = {
        -- The particle starts invisible, before fully becoming visible 10% in its lifetime.
        { Time = 0,    Value = 0 },
        { Time = 0.1,  Value = 1 },

        -- The particle remains fully visible until it reaches 90% of its lifetime.
        { Time = 0.90, Value = 1 },

        -- The particle spends the last 10% of its lifetime fading away.
        { Time = 1,    Value = 0 }
    },
    ColorKeys = {
        -- Particle starts red and gradually becomes orange throughout its lifetime.
        { Time = 0, Value = KColor(1, 0, 0, 1) },
        { Time = 1, Value = KColor(0.929, 0.439, 0.0784, 1) }
    }
}
2026-10-18.22-37-44.mp4

Note

Similar to how ScaleOverLifetime works, evaluated colors are multiplied by the Particle Emitter's StartColor field.

And that should be it! The behavior of ColorOverLifetime.Mode ("Blend" or "Fixed") and ColorOverLifetime.CurveMode is also identical!

Example: Improved Fires

Back in Managing Particle Emitters, one of our examples was a cool fire effect. We can use ColorOverLifetime and ScaleOverLifetime to greatly improve how it looks.

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)
    }

    flames.ScaleOverLifetime.Enabled = true
    flames.ScaleOverLifetime.Keys = {
        { Time = 0, Value = Vector(0.9, 0.9) },
        { Time = 0.3, Value = Vector(1.3, 1.3) },
        { Time = 1, Value = Vector(0, 0) }
    }

    flames.ColorOverLifetime.Enabled = true
    flames.ColorOverLifetime.Gradient = {
        AlphaKeys = {
            { Time = 0, Value = 0 },
            { Time = 0.05, Value = 1 },
            { Time = 0.6, Value = 1 },
            { Time = 1, Value = 0 }
        },
        ColorKeys = {
            { Time = 0, Value = KColor(1, 1, 1, 1) },
            { Time = 1, Value = KColor(1, 0.6, 0.3, 1) }
        }
    }

    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.ColorOverLifetime.Enabled = true
    embers.ColorOverLifetime.Gradient = {
        AlphaKeys = {
            { Time = 0, Value = 0 },
            { Time = 0.1, Value = 1 },
            { Time = 0.5, Value = 0.5 },
            { Time = 0.75, Value = 1 },
            { Time = 1, Value = 0 }
        },
        ColorKeys = {
            { Time = 0, Value = KColor(1, 1, 1, 1) },
            { Time = 1, Value = KColor(1, 0.6, 0.3, 1) }
        }
    }

    embers:Prewarm(150)
end)
2026-11-22.14-04-04.mp4

Clone this wiki locally