Page 1 of 1

Playing animations

Posted: Mon Oct 10, 2011 9:48 pm
by LuaWeaver
Is there any way to program a .gif or .avi to play in Love?

Also, on a side note, anyway to compress a .gif animation so I can upload it here?

Re: Playing animations

Posted: Mon Oct 10, 2011 11:25 pm
by Taehl
Love doesn't support either of those. You could export the frames as .jpegs and flip through them if it's a short animation, though (I assume it is since you're talking about .gif).

As for making animated .gifs, I normally use VirtualDub. It's a light video processing tool, and can export to .gif.

Re: Playing animations

Posted: Mon Oct 10, 2011 11:26 pm
by StormsAndOceans
You could use each frame of the .gif as the animation like this:

Code: Select all

function love.load() 
	frame1 = love.graphics.newImage("x.png") 
	frame2 = love.graphics.newImage("y.png")
end 



function love.update(TimeInSeconds) 
	if TimeInSeconds == 1 then 
		love.graphics.draw(frame1, xpos, ypos) 
	elseif TimeInSeconds == 2 then 
		love.graphics.draw(frame2, xpos, ypos) 
		TimeInSeconds = 0 
	end 
end 
	
My apologies for icky or invalid code. Still kinda new at this. There's also probably a better way to reset TimeInSeconds.

Re: Playing animations

Posted: Mon Oct 10, 2011 11:48 pm
by kraftman
the value passed to love.update is actually the time since the last frame: so while it is in seconds, it is usually very low (0.016 for 60fps)
so if, for example, you wanted something to occur roughly every second, you would do something like:

Code: Select all

local timer = 0
local interval = 1

function love.update(dt)
	timer = timer + dt
	if timer > 1 then
		timer = timer -interval
		--do stuff
	end
end
EDIT:
Also note that the screen is cleared between love.update and love.draw, so any draws inside love.update wont show.

Re: Playing animations

Posted: Tue Oct 11, 2011 6:11 am
by Robin
What's also often done is placing all the frames of an animation on a single image, and using a quad that changes its viewport to animate.

Re: Playing animations

Posted: Tue Oct 11, 2011 8:32 am
by miko
LuaWeaver wrote:Is there any way to program a .gif or .avi to play in Love?
*.avi will not work without video support, so no way.
*.gif animation will not work directly, you will need to convert it to the series of frames. Beware, optimized animated gif is not just a sequence of frames - it can depend on the previous frame's content. Check this out for decompositing the animation:
http://www.imagemagick.org/Usage/anim_basics/

Re: Playing animations

Posted: Tue Oct 11, 2011 2:28 pm
by tentus
How has no one mentioned AnAL yet?

Re: Playing animations

Posted: Tue Oct 11, 2011 2:41 pm
by miko
tentus wrote:How has no one mentioned AnAL yet?
Because OP asked about *.avi movies or *.gif animations, none of which are directly supported by AnAL?

Re: Playing animations

Posted: Tue Oct 11, 2011 5:36 pm
by tentus
miko wrote:
tentus wrote:How has no one mentioned AnAL yet?
Because OP asked about *.avi movies or *.gif animations, none of which are directly supported by AnAL?
But AnAL does do the next best thing. :huh: Why force a confused newcomer to write their own animation system when we already have one that works?

Re: Playing animations

Posted: Wed Oct 12, 2011 1:37 am
by LuaWeaver
Thanks guys. :neko: