Anima Minimal Version With Example

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Anima Minimal Version With Example

Post by YoungNeer »

In previous post we talked about the recent addition to Anima - about the typing animation feature. But there's much more to Anima than just typing. And this post will not cover all of it - but only the most frequently used functions. Infact now there are two files - Anima_min.lua and Anima.lua the former which is the minimal version and the latter the full version (which includes staging, rolling back animation,etc) which will not be cover in this post.

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
The animation is currently very slow so I recommend you add this to love.load function :-

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
Assuming you used the same image I used - you should get this output:-

Image

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 note that by default repeat means infinite repeat but you can change that. Anyways for now we want infinte repeat. So we only add the above to love.load

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)
If you did everything right then you should see an axe moving up and down. You can try changing animaxe:render with love.graphics.draw to get an idea of what Anima is basically doing. Anyways I've already done that in source and here's how it looks like-

Image

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
And I'm skipping the rendering part (cause it's the same as before) but anyways here's how the source-file from the zip look:-

Image

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)
And this is how the source in the zip-file when executed looks like:-

Image
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
Attachments
anima_demos.zip
(885.36 KiB) Downloaded 273 times
My Github- your contribution is highly appreciated
Post Reply

Who is online

Users browsing this forum: No registered users and 53 guests