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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

Septi wrote:Is something wrong with anim8, or did I do something stupid? Please be forgiving, I'm very new both to Lua and Love.
I wouldn't call it stupid, but you need to change the first line to:

Code: Select all

local anim8 = require '3rdparty.anim8.anim8'
Help us help you: attach a .love.
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 - v1.2.0 released

Post by kikito »

anim8 2.0.0 has been released. The new version is on github.

This release breaks backwards-compatibility significantly.

I've updated the OP with a changelog of the most important changes, and updated the demo to reflect them.

Regards!
When I write def I mean function.
a7s1h1
Prole
Posts: 12
Joined: Sat May 25, 2013 2:15 pm

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

Post by a7s1h1 »

Hi there!

I have just started dealing with animation and anim8 v2.0.0 is a very useful thing!
The issue which I'm now trying to settle is how to make the animation end be a condition.
I mean if I have, for example, such a grid:

Code: Select all

anim=anim8.newAnimation(image('1-18',1), 0.1)
, I'd like to be able to do something like that:

Code: Select all

if <animation ended, i.e. the frame of the current animation is 18 (or 1, if it pauses at start)> then
<code>
end
Will be thankful for any ideas.
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.0.0 released

Post by kikito »

It is usually better to test for time, not for frames. I say this because an animation can be on its last frame without "ending" (for example, the last frame could take several seconds).

If you want to get the frame index, use anim.position:

Code: Select all

if anim.position == 4 then
  <do something when animation enters last frame>
end
I prefer using the "onLoop" function (new since 2.0). It is automatically invoked when an animation reaches the end of the last frame, instead of the beginning of its last frame. You can set it up when creating the animation:

Code: Select all

local anim = anim8.newAnimation(g('1-4',1), 0.1, function()
  <do something when animation last frame finishes>
end
You can also set it up after having created the animation:

Code: Select all

local anim = anim8.newAnimation(g('1-4',1), 0.1)
...
anim.onLoop = function()
  <do something when animation last frame finishes>
end
When I write def I mean function.
a7s1h1
Prole
Posts: 12
Joined: Sat May 25, 2013 2:15 pm

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

Post by a7s1h1 »

onloop is just what I needed, thanks a lot!!! :awesome:
a7s1h1
Prole
Posts: 12
Joined: Sat May 25, 2013 2:15 pm

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

Post by a7s1h1 »

I'm facing one more issue.
There is some object, which has a random animation from time to time (just like in many platformer games, when you don't touch any key for a while). The problem is that sometimes my animation timer turns on at the time unknown to me and after it reaches 0, it triggers a new animation, so the current one is interrupted by a new one. I doublechecked all the pieces of my code to find that ugly trigger, but to no avail. Then I decided to put the condition before each time the timer is turned on, something like this:

Code: Select all

if <current animation (player.anim) is on> then
    player.timer=4
end
So, the question is "Is there any way to check if the animation is currently on or not?"
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.0.0 released

Post by kikito »

Hi there,
a7s1h1 wrote:The problem is that sometimes <something happens but I don't know why>. I doublechecked all the pieces of my code to find that ugly trigger, but to no avail. Then I decided <to do something else which doesn't fix the issue, but masks it>
Every time you find yourself in that situation, stop. Usually masking the real issue is not a good solution. Keep chasing the problem, sleep on it, add lots of prints, or even rewrite the whole thing, until you understand clearly what the issue is. Don't bury it with more code that masks the issue. You would be just laying traps for your future self.

It's good to spend time getting the foundations right, before building on top of them; otherwise when the house is half-built, it'll collapse.
a7s1h1 wrote:So, the question is "Is there any way to check if the animation is currently on or not?"
Well, it depends on what you mean by "on". If you mean "playing", yes, you can check that by doing if anim.status == "playing" then [...] .

However I don't recommend it. The reason is that you would be using animations for something they are not designed for.

Animations should change according to what your code tells them, like this:

Code: Select all

if player:isDying() then
  player.dyingAnimation:setFrame(1)
  player.setAnimation(player.dyingAnimation)
end
You are trying to do it the other way around - the animation is controlling your code.

Code: Select all

if anim.status == "playing" then
  <other game code>
end
Let me use an analogy. Imagine that you are doing a platformer, where the player is mostly green and the platforms are mostly red. If you coded it the way you are attempting to use animations, you would be drawing the player and the platforms on the screen, and then reading some pixel colors from the screen to detect if the player was on a platform (instead; you should use the player and platform coordinates and detect how they collide with maths).

I strongly recommend going back to your code and understanding what really happens there. If you need help, I recommend opening a post in the support forum and putting a *.love file there, so others can help you (please don't upload it directly on this thread, since it seems that anim8 is not your real problem here).

In any case, good luck solving your issues!
When I write def I mean function.
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 »

I have released anim8 v2.1.0. The only thing it adds is compatibility with LÖVE 0.9. I've updated the OP with the details.
When I write def I mean function.
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 »

Great! <3
Now I only need Advanced Tile Loader 0.9 : 3 :
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

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

Post by MadByte »

pacman wrote:Great! <3
Now I only need Advanced Tile Loader 0.9 : 3 :
here, does work for me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest