Page 1 of 1

Animation order

Posted: Mon Mar 28, 2011 11:15 pm
by spidarmen
Hi all,

I just started using Love, and am wondering how to make an animation play after a previous animation has finished playing. I have been searching for some type of wait or sleep command, but had no luck.

Any help is appreciated!

Re: Animation order

Posted: Tue Mar 29, 2011 12:54 am
by EmmanuelOga
you'll need to have a count of the elapsed time. In its rawest form:

Code: Select all

local phase = 1
function love.draw()
  if phase == 1 then
    -- do stuff
  elseif phase == 2 then
    -- do stuff
    -- etc...
  end
end

local elapsed = 0
local PHASE1_TIME = 2 -- seconds
function love.update(dt)
  elapsed = elapsed + dt
  if elapsed > PHASE1_TIME then phase = 2 end
end
You can cleanup a lot that code by using some sort of timer, like the one included in HUMP, which works kind of like javascript's setTimeout and setInterval.

https://github.com/vrld/hump/blob/master/timer.lua

EDIT: with hump's timer it would be something like: (docs at http://vrld.github.com/hump/#timer)

Code: Select all

Timer = require "hump.timer"

local phase = 1
Timer.add(5, function()  -- change to phase 2 in 5 seconds 
  phase = 2
  Timer.add(10, function()  --after changing to phase 2, switch to phase 3 in 10 seconds. 
    phase = 3
  end)
end)

function love.draw()
  if phase == 1 then
    -- do stuff
  elseif phase == 2 then
    -- do stuff
    -- etc...
  end
end

function love.update(dt)
  Timer.update(dt)
end
If you need full-blown tweened animations, check https://github.com/EmmanuelOga/tweener.

Re: Animation order

Posted: Tue Mar 29, 2011 6:37 am
by RPG
lQuery framework isn't complete, but consists powerful animation queues like jQuery in JavaScript. Maybe this is frameork you looking for:)

http://love2d.org/forums/viewtopic.php?f=5&t=2570

Queued animations:
http://love2d.org/forums/viewtopic.php? ... 341#p27341

Re: Animation order

Posted: Tue Mar 29, 2011 9:00 pm
by spidarmen
Thanks for the info!
I am having some trouble getting HUMPs timer to work though, I am getting an error with "Timer = require "hump.timer", module not found.
I have timer.lua in the root of the project folder, and it is required in main.lua. Is there anything else I must do to use that module?

Re: Animation order

Posted: Tue Mar 29, 2011 9:06 pm
by EmmanuelOga
spidarmen wrote:Thanks for the info!
I am having some trouble getting HUMPs timer to work though, I am getting an error with "Timer = require "hump.timer", module not found.
I have timer.lua in the root of the project folder, and it is required in main.lua. Is there anything else I must do to use that module?
Try putting it on hump/timer.lua.

Re: Animation order

Posted: Tue Mar 29, 2011 9:07 pm
by BlackBulletIV
spidarmen wrote:Thanks for the info!
I am having some trouble getting HUMPs timer to work though, I am getting an error with "Timer = require "hump.timer", module not found.
I have timer.lua in the root of the project folder, and it is required in main.lua. Is there anything else I must do to use that module?
You're requiring it wrong. You need to put it into a folder called hump. This is because when Lua sees a dot in a require path, it changes it to a forward slash (/). Therefore it's looking at: hump/timer.lua.

EDIT: Ninja'd. Lol.

Re: Animation order

Posted: Tue Mar 29, 2011 9:41 pm
by spidarmen
Ah, that would be the problem.
Thanks for the speedy reply!