Anyways let's get started already.
1. Your First Animation:-
Code: Select all
Anima=require 'Anima_min.lua'
--And since we are not using any advanced features (like staging,rollBack,etc) we will use the minimal version
function love.load()
simpleAnim=Anima:init()
simpleAnim:startNewAnimation('scale',1,1)
end
function love.update(dt)
simpleAnim:update()
end
function love.draw()
simpleAnim:render(img,400,300,0,0,0,img:getWidth()/2,img:getHeight()/2)
--assuming we have an image data file 'img'
end
Code: Select all
simpleAnim:setScaleSpeed(0.05,0.05)
--[u]setScaleSpeed[/u] takes two parameters sx and sy which denotes the scaling speed per frame
2. Axe Animation:-
From now on I'm only going to show the essential code. For full source you can download the zip file attached.
Code: Select all
animaxe:startNewAnimation('move',0,-5)
--move 5 pixels up (frame by frame)
animaxe:setSpeed(0,0.5)
--same as [u]setMoveSpeed[/u] (in this context); takes two parameters x and y which denotes the moving speed per frame
--When we have to repeat an animation we do this:-
animaxe:setRepeat(false,true)
--Same as [i]setRepeatMove[/i] (in this context); this means don't repeat movement along x but along y
And update would be the same as before but rendering method would be a little different - since we are rendering a quad!
Code: Select all
animaxe:renderQuad(axe,axeQuad[frame],400,300)
--here frame is the current frame (this is a non-Anima thing so is not explained in detail)
3. Car Animation:-
The car-body will move in the same way as the axe moved- up and down, so we will not worry about that. But what about the wheels- well you can do setRepeatRotation but the problem is that would flip the direction in which it is rotating and we don't want that. So the way will do this is:-
Code: Select all
function love.load()
tireAnim:startNewAnimation("rotate",math.pi*2)
--rotate the tire 360 degrees
end
function love.update()
tireAnim:update()
if tireAnim:animationOver() then
tireAnim:restartAnimation()
end
end
4. Shaky Animation:-
In this example we will talk about the recent addition to Anima which allows you to repeat animation a number of times (not just infinite). This can be useful for getting a shaky effect!
I won't show the entire code but here's the gist of it:-
Code: Select all
windowAnim:startNewAnimation('move',5)
windowAnim:setRepeat(true)
windowAnim:repeatTimes(5)
Please note that the typing animations are not discussed here.
You can find them in this link
The full project is at github
https://github.com/YoungNeer/lovelib/tree/master/Anima
Your contribution will be highly appreciated