Playing animations

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Playing animations

Post 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?
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Playing animations

Post 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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
StormsAndOceans
Prole
Posts: 18
Joined: Sun Oct 09, 2011 1:12 am

Re: Playing animations

Post 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.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Playing animations

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Playing animations

Post 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.
Help us help you: attach a .love.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Playing animations

Post 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/
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Playing animations

Post by tentus »

How has no one mentioned AnAL yet?
Kurosuke needs beta testers
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Playing animations

Post 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?
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Playing animations

Post 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?
Kurosuke needs beta testers
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Playing animations

Post by LuaWeaver »

Thanks guys. :neko:
"your actions cause me to infer your ego is the size of three houses" -finley
Post Reply

Who is online

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