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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 1:40 am, edited 2 times in total.
User avatar
pacman
Citizen
Posts: 81
Joined: Thu Mar 14, 2013 4:10 pm

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by pacman »

You are all golden :*
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by zell2002 »

hi
how do you tell the grid/animation to play the frames in a specific order ?
as in:

Code: Select all

[3], [6], [9]
[2], [5], [8]
[1], [4], [7]
- a sprite of 3 by 3

i want to start at the bottom left, 1, and then move sequentially through the sprite.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by kikito »

zell2002 wrote:hi
how do you tell the grid/animation to play the frames in a specific order ?
as in:

Code: Select all

[3], [6], [9]
[2], [5], [8]
[1], [4], [7]
You need an animation that:
  • For the first 3 frames, leaves X=1 and moves Y from 3 to 1
  • For next 3 frames, leaves X=2 and moves Y from 3 to 1
  • For the last 3 frames, leaves X=3 and moves Y from 3 to 1
In other words:

Code: Select all

local g = anim.newGrid(32, 32, 256, 256) 
local fancyAnimation = anim.newAnimation(g(1,'3-1', 2,'3-1', 3,'3-1'), 0.1) 
Notes:
  • You will need to replace the newGrid params with the right frame & image dimensions.
  • You will also probably need to tweak the frame durations (the 0.1)
  • That kind of order is unusual, the usual one starts from left to right, and then goes from top to bottom. This is the order that anim8 follows by default. If you rearrange your frames so they look like this:

Code: Select all

[1], [2], [3]
[4], [5], [6]
[7], [8], [9]
Then the code to load it gets much simpler:

Code: Select all

local fancyAnimation = anim.newAnimation(g('1-3', '1-3'), 0.1) 
When I write def I mean function.
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by zell2002 »

lol ye the order is VERY odd. ive seen a few like this (i didnt make it)
i would have made it like any sane person - top left to top right.

i think i will edit it.

cheers for the info! that will be most useful (will test it now so ive got the understanding under my belt)
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by CaptainMaelstrom »

Hey kikito. I'm having some issues with anim8 :| .

1.) The github wiki mentions that the "onLoop" parameter is passed two parameters: the animation Instance, and a loop count. My tests have verified that this isn't the case. (.love attached, the purple number is the animation, the white number is the loop count reported by the onLoop parameter).

I believe your problem lies within lines 230-232 of the v 2.1.0 code:

Code: Select all

 
local loops = math.floor(self.timer / self.totalDuration)
  if loops ~= 0 then
    self.timer = self.timer - self.totalDuration * loops
where self.timer never rises above self.totalDuration so loops never surpasses a value of 1.

2.) I tried to make a simple ping-pong function (animation would go 1 - 2 - 3 - 2 - 1 -2 - 3 ...) but discovered that there was no way to get the frame array from an animation once it's been created. Is there an easy way to achieve ping-ponging? (perhaps via the onLoop optional parameter?)

Otherwise, I'm enjoying using anim8. Thanks.
Attachments
onLoopIsBroken.love
(7.31 KiB) Downloaded 369 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by kikito »

Hi CaptainMaelstrom,

1) onLoop works as intended - you just didn't understand how it works. Maybe I didn't explain it properly. Let me try again.

The logic is the following:

Every time you update the animation (with :update(dt)), an internal counter is increased to see if the animation has "reached its end".
  • If it hasn't, then onLoop it is not called.
  • If it has, then onLoop is called, and you get how many loops have been completed on the last update - not from the beginning of the animation.
This means that loops is often 1 (when it's 0, onLoop is not even called). But in weird cases it can be more. For example, if you have one animation which takes 2 seconds to play and you invoke animation:update(6), the onLoop callback will be called once with 3 as a parameter.

In order to fix your demo, you just need to change this:

Code: Select all

myOnLoop = function(animInst, loops)
	count = loops
end
By this:

Code: Select all

myOnLoop = function(animInst, loops)
	count = count + loops
end
2) You can use onLoop to make "bouncing" animations, but it's easier to simply include the whole list of frames. When an animation does "ping pong" between frames 1,2,3 & 4, it also works in a loop; it just that the loop is a bit longer and looks like this: 1,2,3,4,3,2 (and then go back to the 1st, starting a new loop). Since you can use intervals, it's really short to write those down if the frames are in the right order on the grid. It'll look similar to

Code: Select all

anim.newAnimation({'1-4',1,'3-2',1}, 0.1)
I hope this helps!
Last edited by kikito on Sat Sep 27, 2014 12:48 am, edited 1 time in total.
When I write def I mean function.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by CaptainMaelstrom »

Ah, thanks kikito.

The loops counting explanation makes sense. I've never updated more than 17ms at a time, but I can see why I might want to at some point.

The ping-ponging solution works for me, too. I appreciate you clearing this up for me. Back to making games! :D
User avatar
konacake
Prole
Posts: 11
Joined: Mon Mar 03, 2014 4:35 am

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by konacake »

Hi, this is a really great library, it saved me a lot of headaches trying to figure out how to animate on my own.

I was wondering, could I get a detailed explanation of frames argument for newAnimation? It confuses me greatly, I have no idea how it works or what logical order it follows, I've only been able to make arbitrary guesses for what to pass it by browsing this thread.
For example, I have a sprite that needs to show the second frame, then the first, then the second, then the third, then loop. I've already got it doing that, so I don't need help, I just want to know how it works so I don't get stuck again. I would have assumed passing ('1-2, '1-1', '1-3', '1-2') would suffice, but that causes the animation to flip out and show a bunch of different frames that I don't want. I tried flipping the rows/columns around but it was the same mess. Then I find out the proper way to do it is (2, '1-1', 1, '1-1', 2, '1-1', 3, '1-1'). What's with the lone numbers in front of the row/column definitions, and why do the row/columns have to be 1-1 instead of the actual frame placements ('1-2', '1-3', etc.)? I can't see the order here, I have no idea how this argument system works. Thanks for your time. It's a wonderful and easy to use library, I just don't get this one part of it.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Library] anim8 - An animation library - v2.1.0 released

Post by kikito »

konacake wrote:For example, I have a sprite that needs to show the second frame, then the first, then the second, then the third, then loop.
In anim8 the frames are not "first", "second" or "third".

The frames of a grid are divided into rows and columns. In order to specify a frame you need two values (the row and the column). You can't say "first". You have to say "first row and first column". Or "first row, second column", or whatever is appropiate. You just can't use a single number. The "row" is called "x" and the "column" is called "y". They start at 1, and they go from left to right and from top to bottom respectively.

Think about the parameters you pass as groups of x and y parameters. For example:

Code: Select all

(1,1, 2,1, 3,1)
That's the frame on the first column, first row (1,1), then second column, first row (2,1), then third column, first row(3,1). And then it loops.

Notice that all the frames are on the same row on this case. Putting animations in this order is usual, so if you have an animation like this you can use a string for the row like this:

Code: Select all

('1-3', 1)
That produces the same frames as the version above. The first parameter is "x", and it "goes from 1 to 3". The second parameter is a number, so it "stays" at 1 while x changes. So it produces (1,1), then (2,1) and finally (3,1).

Let me know if this helps you.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests