So, these are legal (I'm only going to modify the third parameter):Jack Dandy wrote:In the readme in https://github.com/kikito/anim8, it says:Now, let's say I supply my own little function.anim8 readme wrote:onLoop is an optional parameter which can be either a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops".It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
But I don't exactly understand, how am I supposed to access the two parameters you talked about in the quote?
For example, the following didn't work.Code: Select all
slashAnim = anim8.newAnimation(animgrid('1-6',1), 0.04, (function(a,b) DRAWSLASH=false a:pauseAtEnd() end))
Code: Select all
someAnim1 = anim8.newAnimation(animgrid('1-6',1), 0.04) -- or an explicit nil, since it's optional.
someAnim2 = anim8.newAnimation(animgrid('1-6',1), 0.04, 'pauseAtEnd') -- this is the string version.
Animations have the following methods:
animation:update(dt)
animation:draw(image, x,y, angle, sx, sy, ox, oy, kx, ky)
animation:gotoFrame(frame)
animation:pause()
animation:resume()
animation:clone()
animation:flipH()
animation:flipV()
animation:pauseAtEnd() --Moves the animation to its last frame and then pauses it.
animation:pauseAtStart() --Moves the animation to its first frame and then pauses it.
animation:getDimensions()
(...)
The third type would be a function:
Code: Select all
someAnim3 = anim8.newAnimation(animgrid('1-6',1), 0.04, function(animationInstance,elapsedLoops) --[[do something with animInstance using elapsedLoops...--]] end)
-- or alternatively:
local function animCallback(instance,loops)
-- something
end
someAnim3 = anim8.newAnimation(animgrid('1-6',1), 0.04, animCallback)