Animation order

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
spidarmen
Prole
Posts: 3
Joined: Mon Mar 28, 2011 11:07 pm

Animation order

Post 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!
User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Animation order

Post 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.
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Animation order

Post 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
spidarmen
Prole
Posts: 3
Joined: Mon Mar 28, 2011 11:07 pm

Re: Animation order

Post 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?
User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Animation order

Post 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.
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Animation order

Post 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.
spidarmen
Prole
Posts: 3
Joined: Mon Mar 28, 2011 11:07 pm

Re: Animation order

Post by spidarmen »

Ah, that would be the problem.
Thanks for the speedy reply!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 84 guests