Page 2 of 9

Re: [Library] anim8 - A different animation library

Posted: Thu Sep 27, 2012 2:46 pm
by kikito
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.

Re: [Library] anim8 - A different animation library

Posted: Fri Oct 05, 2012 4:30 pm
by dark_on_5
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 :3

Re: [Library] anim8 - A different animation library

Posted: Sat Oct 06, 2012 5:40 am
by T-Bone
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 :3
You're doing it wrong. Show us your code.

Re: [Library] anim8 - A different animation library

Posted: Sat Oct 06, 2012 11:17 am
by kikito
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.

Re: [Library] anim8 - A different animation library

Posted: Sat Oct 06, 2012 3:24 pm
by dark_on_5
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 :)

Re: [Library] anim8 - A different animation library

Posted: Sun Oct 07, 2012 8:21 pm
by kikito
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.

Re: [Library] anim8 - A different animation library

Posted: Mon Oct 08, 2012 6:51 pm
by dark_on_5
Thank you, yes, the problem was the ":", I'm so noob with LUA :awesome:

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

So, thank you again!

Re: [Library] anim8 - A different animation library

Posted: Fri Dec 07, 2012 12:48 am
by kikito
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).

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

Posted: Fri Dec 07, 2012 4:22 am
by Mogex
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)


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

Posted: Fri Dec 07, 2012 8:51 am
by kikito
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.