Code: Select all
print("GSLIB LOADED...")
local gs = {}
gs.__index = gs
local i = ""
function gs:Init(x)
i = x
print(x.." Initialized!")
end
setmetatable(gs, {
_call = function(cls,...)
return cls.new(...)
end,
})
function gs.NewGif(init)
local self = setmetatable({},gs)
local frames = love.filesystem.getDirectoryItems(init)
print("Loading Frames From..."..init)
self.image = {}
self.index = 1
self.timer = 0
self.frames = 0
for i = 1, #frames do
print("Frame: "..i.." "..frames[i])
self.image[i] = love.graphics.newImage(init..frames[i])
self.frames = i
end
return self
end
function gs.UpdateGif(self,dt)
self.timer = self.timer + dt
if self.timer >= dt then
if self.index >= self.frames then
self.index = 1
print(self.index)
elseif self.index <= self.frames then
self.index = self.index + 1
end
self.timer = 0
end
end
function gs.DrawGif(self,x,y)
love.graphics.draw(self.image[self.index],x,y)
end
return gs
- Create a Folder in your games main folder and call if GIFS
- Upload and split your gif into this amazing website. http://ezgif.com/split
- Download all the frames
- Create a new folder in the folder GIFS
- Place all your frames into the New Folder you created
Set Up:
In your main.lua type this:
GS = require"GSLIB"
Then in love.load type this:
GS:Init("GSLIB")
And Done!
How To Create A Gif(love.load()):
dir1 = "GIFS/MyGif/"
myGif = GS.NewGif(dir1)
How To Draw And Update It:
Update:
myGif:UpdateGif(dt,speed)
Draw:
myGif:DrawGif(x,y)
Thats It!
Example: