## [Library] anim8 - An animation library - v2.3.0 released

Showcase your libraries, tools and other projects that help your fellow love users.
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

### Re: [Library] anim8 - A different animation library

clofresh wrote:I love anim8! Makes animation so much easier.

Question: Is there a way to ask an animation for the bounding box of the non-transparent area of the current frame? It'd like to use it for collision detection where collisions correspond directly to the drawn pixels, but a grid cell is the size of the largest animation frame so many frames have a padding of transparent pixels to make them uniform size. Doesn't have to be the exact shape, a rectangle would do fine.
Sorry, no - anim8 has no idea of what's inside the frames. It just knows how and when to draw them.

That said, you can get the current frame (a Quad) like this:

Code: Select all

-- assuming that a is an animation
local currentFrame = a.frames[a.position]
You will also need the image (or rather: the ImageData) you want to calculate the bounding box about; quads exist independently of them. Once you have the quad and the imageData, you can parse all the pixels of the later to get the bounding box.

But parsing images like that is a slow operation in love. You don't want to be doing that on every frame of animation. I strongly recommend you having that information pre-calculated - manually, or at the beginning of the game - instead. It could slow down your game significantly.
When I write def I mean function.
dark_on_5
Prole
Posts: 5
Joined: Fri Oct 05, 2012 4:19 pm
Location: Bilbao, Spain
Contact:

### Re: [Library] anim8 - A different animation library

Hi, I'm new in LUA, and I have some questions with this library

I need to put all the code in the main.lua? (love.load(), love.draw(), love.update(dt)...) I tried to load the animation in other .LUA file (for example, menu.load(), menu.draw()...) and I received this error:

Code: Select all

anim8.lua:255: attempt to perform arithmetic on local 'dt' (a table value)

Traceback:

anim8.lua:255: In function 'update'
res/lua/menu.lua:34: in function 'update'
main.lua:65: in function 'update'
[C]: in function 'xpcall'
Thanks in advance
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

### Re: [Library] anim8 - A different animation library

dark_on_5 wrote:Hi, I'm new in LUA, and I have some questions with this library

I need to put all the code in the main.lua? (love.load(), love.draw(), love.update(dt)...) I tried to load the animation in other .LUA file (for example, menu.load(), menu.draw()...) and I received this error:

Code: Select all

anim8.lua:255: attempt to perform arithmetic on local 'dt' (a table value)

Traceback:

anim8.lua:255: In function 'update'
res/lua/menu.lua:34: in function 'update'
main.lua:65: in function 'update'
[C]: in function 'xpcall'
Thanks in advance
You're doing it wrong. Show us your code.
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

### Re: [Library] anim8 - A different animation library

According to your error message, on the menu.lua file you are invoking some animation function the wrong way, or with the wrong parameters. It's also possible that you are not using the most current version of anim8, since the most current one doesn't invoke any function in line 255. Have you maybe made some additions?

That's all I can tell you without seeing your source code.
When I write def I mean function.
dark_on_5
Prole
Posts: 5
Joined: Fri Oct 05, 2012 4:19 pm
Location: Bilbao, Spain
Contact:

### Re: [Library] anim8 - A different animation library

Here is my code:

https://dl.dropbox.com/u/72131301/mygam ... errors.zip

There are 2 versions, the one with all in main.lua (working), and the one in menu.lua (with errors).

Thank you again
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

### Re: [Library] anim8 - A different animation library

I'm not sure of what your code does. First some notes:
• Indent your code before asking for help. Unindented code is very tiresome to go over, especially for people not familiar with it.
• You don't have to require 'anim8' twice. Just leave the second line (the one that says anim8 = require 'anim8')
The problem (I think) is in main.lua, line 34. You have this:

Code: Select all

intro:update(dt) 
But you probably meant this:

Code: Select all

intro.update(dt) 
Otherwise, the first parameter you pass to the update function is the "intro" table.

Another way of fixing this is changing the way the menu.update function is declared; you can declare it like this:

Code: Select all

-- inside menu.lua
function menu:update(dt) -- two dots instead of one
Any of these solutions should solve your issue.
When I write def I mean function.
dark_on_5
Prole
Posts: 5
Joined: Fri Oct 05, 2012 4:19 pm
Location: Bilbao, Spain
Contact:

### Re: [Library] anim8 - A different animation library

Thank you, yes, the problem was the ":", I'm so noob with LUA

Okay, next time I have a issue I'll post my code indented.

So, thank you again!
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

### Re: [Library] anim8 - A different animation library

Version 1.2.0 is out!

Change log:
• The clone() method, which existed before, has been properly documented
• I've added two methods to animations, called flipH and flipV. These merely toggle two new internal booleans called flippedH and flippedV. When any of those is turned on, the quads are drawn "mirrored". These two methods do not create a new animation; they modify the existing one. If you want to create two separate animations, you must use clone, like this: animation2 = animation:clone(); animation2:flipV()
I'm updating the OP with a new demo that allows flipping the planes by pressing any key (except esc, which exists).
Last edited by kikito on Fri Dec 07, 2012 12:22 pm, edited 1 time in total.
When I write def I mean function.
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

### Re: [Library] anim8 - An animation library - v1.2.0 released

I got an annoying error:

Anim8.lua: Incorrect parameter type: expected userdata.

This is all anim8 related code I've used.

Code: Select all

local anim8 = require 'anim8'
local sheet1, animation

image = love.graphics.newImage("sheet1.png")
local g = anim8.newGrid(32, 32, image:getWidth(), image: getHeight())
animation = anim8.newAnimation('loop', g('1,1-8'), 0.1)

animation:update(dt)


kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

Can you give me the complete source code, or at least the line where the error happened? What version of anim8 are you using?

EDIT: the only place where a userdata is actually needed is on the draw part, which you are not showing in your post. Please show me how you are drawing the animation at least.
When I write def I mean function.

### Who is online

Users browsing this forum: No registered users and 6 guests