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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
zorg
Party member
Posts: 2286
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg » Tue Oct 18, 2016 4:18 pm

Jack Dandy wrote:In the readme in https://github.com/kikito/anim8, it says:
anim8 readme wrote:onLoop is an optional parameter which can be either a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops".It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
Now, let's say I supply my own little function.
But I don't exactly understand, how am I supposed to access the two parameters you talked about in the quote?

For example, the following didn't work.

Code: Select all

slashAnim = anim8.newAnimation(animgrid('1-6',1), 0.04, (function(a,b) DRAWSLASH=false  a:pauseAtEnd() end))
So, these are legal (I'm only going to modify the third parameter):

Code: Select all

	someAnim1 = anim8.newAnimation(animgrid('1-6',1), 0.04) -- or an explicit nil, since it's optional.
	someAnim2 = anim8.newAnimation(animgrid('1-6',1), 0.04, 'pauseAtEnd') -- this is the string version.
The readme goes on to list the animation methods (detailed blocks removed), probably not a good idea to use some/most of them though:
Animations have the following methods:
animation:update(dt)
animation:draw(image, x,y, angle, sx, sy, ox, oy, kx, ky)
animation:gotoFrame(frame)
animation:pause()
animation:resume()
animation:clone()
animation:flipH()
animation:flipV()
animation:pauseAtEnd() --Moves the animation to its last frame and then pauses it.
animation:pauseAtStart() --Moves the animation to its first frame and then pauses it.
animation:getDimensions()
(...)

The third type would be a function:

Code: Select all

	someAnim3 = anim8.newAnimation(animgrid('1-6',1), 0.04, function(animationInstance,elapsedLoops) --[[do something with animInstance using elapsedLoops...--]] end)
	-- or alternatively:
	local function animCallback(instance,loops)
		-- something
	end
	someAnim3 = anim8.newAnimation(animgrid('1-6',1), 0.04, animCallback)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
Jack Dandy
Prole
Posts: 34
Joined: Mon Sep 08, 2014 4:26 pm

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

Post by Jack Dandy » Tue Oct 18, 2016 7:14 pm

Thanks for the clear-up. :)

User avatar
piotrek75
Prole
Posts: 9
Joined: Tue Oct 18, 2016 7:43 pm

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

Post by piotrek75 » Sat Nov 05, 2016 9:36 am

Hello, FYI, I could not understand how to get a CURRENT frame count and TOTAL frame count for an animation.

So I modified a bit the anim8.lua by adding:

Code: Select all

function Animation:getCurrentFrameCounter()
  return self.position
end

function Animation:getTotalFrameCounter()
  return #self.frames
end
(Posting this here as it may be usefull for some of you and I still do not get the process of having a change validated and pushed to the main anim8 GitHub repository)

User avatar
modiX
Citizen
Posts: 73
Joined: Mon Dec 04, 2017 1:47 am

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

Post by modiX » Tue Jan 02, 2018 12:34 pm

Does anybody know how I can change the duration of a running animation or do I have to create a new animation?
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█

Visual Studio Code Template

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

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

Post by kikito » Tue Jan 02, 2018 2:45 pm

You can make animations go faster or slower by altering the dt you pass them:

Code: Select all

-- if instead of anim:update(dt) you do:
anim:update(dt * 2)   -- anim will run twice as fast.
anim:update(dt * 0.5) -- anim will run twice as slow.
So you can store that coefficient in a variable and multiply it on the update section. You can use this to do cool stuff like time manipulation, or make the gears of a train engine move in synchronicity with its velocity, using a single animation.

Apart from that, you can always create a new animation, of course.
When I write def I mean function.

User avatar
modiX
Citizen
Posts: 73
Joined: Mon Dec 04, 2017 1:47 am

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

Post by modiX » Tue Jan 02, 2018 4:17 pm

kikito wrote:
Tue Jan 02, 2018 2:45 pm
You can make animations go faster or slower by altering the dt you pass them:

Code: Select all

-- if instead of anim:update(dt) you do:
anim:update(dt * 2)   -- anim will run twice as fast.
anim:update(dt * 0.5) -- anim will run twice as slow.
So you can store that coefficient in a variable and multiply it on the update section. You can use this to do cool stuff like time manipulation, or make the gears of a train engine move in synchronicity with its velocity, using a single animation.

Apart from that, you can always create a new animation, of course.
Yet so simple, how could I miss that, great. Thank you so much! :awesome:
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█

Visual Studio Code Template

Timon
Prole
Posts: 2
Joined: Fri Jan 26, 2018 12:08 pm

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

Post by Timon » Fri Jan 26, 2018 1:17 pm

Dear Kikito, thanks you for anim8!

Please explain - in Animations part i see
onLoop is an optional parameter which can be a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops". It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
But bellow i see another description
animation:pauseAtEnd()
Moves the animation to its last frame and then pauses it.
I know that this works as described below - moves the animation to its last frame and then pauses it.

Thanks you again )

User avatar
zorg
Party member
Posts: 2286
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg » Fri Jan 26, 2018 5:11 pm

Timon wrote:
Fri Jan 26, 2018 1:17 pm
...Please explain...
Those two sentences mean the same thing, playing the animation once == looping once, then pausing at the last frame, i.e. the index won't go back to the first frame.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests