kikito / anim8

An animation library for LÖVE
MIT License
730 stars 88 forks source link

Callbacks #8

Closed karai17 closed 10 years ago

karai17 commented 10 years ago

It would be pretty swanky for anim8 to allow callbacks at the end of an animation loop. A potential use case for this would be:

Assume a sprite has many animations, including "idleLeft" and "attackLeft". Once a player uses an attack, we want to switch back to the idle animation.

facing = "attackLeft"

sprites = {
    attackLeft = anim8.newAnimation(g(1-5,1), 0.1, "once", switchToIdle()), -- add more animation modes such as once/justonce
    idleLeft = anim8.newAnimation(g(1-5,2), 0.1)
}

function switchToIdle()
    attackLeft:gotoFrame(1) -- pausing at the end of an animation is super annoying. just setting the animation back to the beginning and leaving its state alone would be ideal.
    facing = "idleLeft"
end

function update(dt)
    sprites[facing]:update(dt)
end
shakesoda commented 10 years ago

the third argument for newAnimation appears to be that: https://github.com/kikito/anim8/blob/master/anim8.lua#L171

karai17 commented 10 years ago

Oh hey, there IS a callback. I'm just a moron.

kikito commented 10 years ago

Don't be too hard on yourself, that happens :) . You were using an old version of anim8, give a look at the change log and the readme!