Skip to content

Animation Events

Sprites emit gfx.ChangeTag when their animation tag changes. Events are emitted to the entity's address in the world's event system.

Available Events

EventWhen It Fires
gfx.ChangeTagWhen the animation tag changes via setTag()

ChangeTag Event

ChangeTag fires when setTag() is called, including the initial tag set during spawn.

Event Properties

PropertyTypeDescription
entityintegerThe entity ID
oldTagstringPrevious animation tag (empty on first load)
newTagstringNew animation tag
animSpriteReference to the Sprite component

Examples

teal
world:observe(entityId, gfx.ChangeTag, function(event)
    print("Entity", event.entity, "changed from", event.oldTag, "to", event.newTag)
end)
teal
world:observe(entityId, gfx.ChangeTag, function(event)
    if event.newTag == "death" then
        world:remove(entityId, PlayerController)
    end
end)
teal
local sounds = {
    walk = love.audio.newSource("sounds/footsteps.ogg", "static"),
    attack = love.audio.newSource("sounds/sword.ogg", "static"),
}

world:observe(entityId, gfx.ChangeTag, function(event)
    local sound = sounds[event.newTag]
    if sound then
        sound:stop()
        sound:play()
    end
end)

Event Lifetimes

Direct constructors such as gfx.ChangeTag(...) allocate a fresh event instance. Internal sprite code uses world:emit(entityId, gfx.ChangeTag, ...), which reuses world-local storage and should be treated as callback-local. Do not store references to event objects received from observers.

teal
local lastTag = ""

world:observe(entityId, gfx.ChangeTag, function(event)
    lastTag = event.newTag
end)