GIFs in love?

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
GamerDMG
Prole
Posts: 1
Joined: Thu May 19, 2016 2:32 pm

GIFs in love?

Post 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 ^^
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: GIFs in love?

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: GIFs in love?

Post 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.
Skeletonxf
Citizen
Posts: 87
Joined: Tue Dec 30, 2014 6:07 pm

Re: GIFs in love?

Post by Skeletonxf »

If you want animation then you can use the video support Love provides with ogg files.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 0 guests