Page 1 of 1

GIFs in love?

Posted: Thu May 19, 2016 5:02 pm
by GamerDMG
I want to make a project for school and asked myself: "Can I use GIFs in love2d?"
So yeah, is there any way you can do. I searched the entire web but found only one therad but the links with the solution weren't avaible anymore. So is there any possibility? pls help ^^

Re: GIFs in love?

Posted: Thu May 19, 2016 5:45 pm
by s-ol
GamerDMG wrote:I want to make a project for school and asked myself: "Can I use GIFs in love2d?"
So yeah, is there any way you can do. I searched the entire web but found only one therad but the links with the solution weren't avaible anymore. So is there any possibility? pls help ^^
why do you need gifs in LÖVE? gifs are a rather terrible format and if you don't need to use them for some very specific reason why would you. LÖVE doesn't support them by default but you could theoretically write your own parser.

Re: GIFs in love?

Posted: Thu May 19, 2016 6:12 pm
by Sheepolution
Welcome!
As far as I know, you can't put gifs in LÖVE. Is it animated images that you want? You can use quads for that.

First you need to turn the gif into a spritesheet. In case you don't have tools for that, you can use http://gif2sprite.com/ (Put it on PNG instead of JPG).

Click on View Sprite, right-click, and download the sprite.

Now in game you load the image

Code: Select all

function love.load()
	image = love.graphics.newImage("spritesheet.png")
Next we need to make quads. With quads we can draw parts of images.

Code: Select all

	quads = {}
	local imgWidth, imgHeight = image:getWidth(), image:getHeight()
	local spriteWidth = imgWidth / FRAMES
	for i=0,FRAMES-1 do
		table.insert(quads, love.graphics.newQuad(i * spriteWidth, 0, imgHeight, imgWidth, imgHeight)
	end
Change FRAMES into the number of frames your animation has.

Now we need a timer

Code: Select all

	timer = 0
end

function love.update(dt)
	timer = timer + dt * SPEED
end
Change speed to make the animation go faster. Now we need to draw it

Code: Select all

function love.draw()
	love.graphics.draw(image, quads[(math.floor(timer) % FRAMES) + 1], 100, 100)
end
Tada.

Or, you know, use a library like anim8.

Re: GIFs in love?

Posted: Sat May 21, 2016 8:34 pm
by Skeletonxf
If you want animation then you can use the video support Love provides with ogg files.