59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
|
x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
|
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
|
local im=love.graphics.newImage(file)
|
|
local _x,_y=im:getDimensions()
|
|
c.Visibility=0
|
|
c.ImageVisibility=1
|
|
c.delay=delay or .05
|
|
c.files={}
|
|
c.AnimStart={}
|
|
c.AnimEnd={}
|
|
for i=0,_y/yd-1 do
|
|
for j=0,_x/xd-1 do
|
|
table.insert(c.files,gui:getTile(im,j*xd,i*yd,xd,yd))
|
|
end
|
|
end
|
|
c:SetImage(c.files[1])
|
|
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
|
c.step.parent=c
|
|
c.rotation=0
|
|
c.step:OnStart(function(step)
|
|
for i=1,#step.parent.AnimStart do
|
|
step.parent.AnimStart[i](step.parent)
|
|
end
|
|
end)
|
|
c.step:OnStep(function(pos,step)
|
|
step.parent:SetImage(step.parent.files[pos])
|
|
end)
|
|
c.step:OnEnd(function(step)
|
|
for i=1,#step.parent.AnimEnd do
|
|
step.parent.AnimEnd[i](step.parent)
|
|
end
|
|
end)
|
|
function c:OnAnimStart(func)
|
|
table.insert(self.AnimStart,func)
|
|
end
|
|
function c:OnAnimEnd(func)
|
|
table.insert(self.AnimEnd,func)
|
|
end
|
|
function c:Pause()
|
|
self.step:Pause()
|
|
end
|
|
function c:Resume()
|
|
self.step:Resume()
|
|
end
|
|
function c:Reset()
|
|
self.step.pos=1
|
|
end
|
|
function c:getFrames()
|
|
return #self.files
|
|
end
|
|
function c:getFrame()
|
|
return self.step.pos
|
|
end
|
|
function c:setFrame(n)
|
|
return self:SetImage(self.files[n])
|
|
end
|
|
return c
|
|
end |