Update Animation.lua
This commit is contained in:
@@ -6,22 +6,30 @@ return function(name)
|
|||||||
|
|
||||||
local animations = {}
|
local animations = {}
|
||||||
local index = 1
|
local index = 1
|
||||||
|
local infinitePlay = false
|
||||||
|
|
||||||
local nextWaitTimer = 0
|
local nextWaitTimer = 0
|
||||||
local lastFunc
|
local lastFunc
|
||||||
|
|
||||||
|
local _OBJ
|
||||||
|
|
||||||
local function onPlay()
|
local function onPlay()
|
||||||
if (animations[index] ~= nil) then
|
if (animations[index] ~= nil) then
|
||||||
animations[index].f(object, index)
|
animations[index].f(object, index)
|
||||||
end
|
end
|
||||||
index = index + 1
|
index = index + 1
|
||||||
if (animations[index] ~= nil) then
|
if(animations[index]==nil)then
|
||||||
if (animations[index].t > 0) then
|
if(infinitePlay)then
|
||||||
timerObj = os.startTimer(animations[index].t)
|
index = 1
|
||||||
else
|
else
|
||||||
onPlay()
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if (animations[index].t > 0) then
|
||||||
|
timerObj = os.startTimer(animations[index].t)
|
||||||
|
else
|
||||||
|
onPlay()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
@@ -44,13 +52,142 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setObject = function(self, obj)
|
||||||
|
_OBJ = obj
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
move = function(self, x, y, time, frames, obj)
|
||||||
|
if(obj~=nil)then
|
||||||
|
_OBJ = obj
|
||||||
|
end
|
||||||
|
if(_OBJ.setPosition==nil)or(_OBJ.getPosition==nil)then return self end
|
||||||
|
local oX,oY = _OBJ:getPosition()
|
||||||
|
if(oX==x)and(oY==y)then return self end
|
||||||
|
|
||||||
|
local xAdd = oX<=x and (x-oX)/frames or (oX-x)/frames
|
||||||
|
local yAdd = oY<=y and (y-oY)/frames or (oY-y)/frames
|
||||||
|
local xInverted,yInverted = oX>x and true or false, oY>y and true or false
|
||||||
|
|
||||||
|
for n=1, math.floor(frames) do
|
||||||
|
local f
|
||||||
|
if(n==frames)then
|
||||||
|
f = function()
|
||||||
|
_OBJ:setPosition(x, y)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f = function()
|
||||||
|
_OBJ:setPosition(math.floor(xInverted and oX+(-xAdd*n) or oX+xAdd*n), math.floor(yInverted and oY+(-yAdd*n) or oY+yAdd*n))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(animations, { f = f, t = time/frames})
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
moveLerp = function(self, x, y, time, obj)
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
|
offset = function(self, x, y, time, frames, obj)
|
||||||
|
if(obj~=nil)then
|
||||||
|
_OBJ = obj
|
||||||
|
end
|
||||||
|
if(_OBJ.setOffset==nil)or(_OBJ.getOffset==nil)then return self end
|
||||||
|
local oX,oY = _OBJ:getOffset()
|
||||||
|
oX = math.abs(oX)
|
||||||
|
oY = math.abs(oY)
|
||||||
|
|
||||||
|
if(oX==x)and(oY==y)then return self end
|
||||||
|
|
||||||
|
local xAdd = oX<=x and (x-oX)/frames or (oX-x)/frames
|
||||||
|
local yAdd = oY<=y and (y-oY)/frames or (oY-y)/frames
|
||||||
|
local xInverted,yInverted = oX>x and true or false, oY>y and true or false
|
||||||
|
|
||||||
|
for n=1, math.floor(frames) do
|
||||||
|
local f
|
||||||
|
if(n==frames)then
|
||||||
|
f = function()
|
||||||
|
_OBJ:setOffset(x, y)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f = function()
|
||||||
|
_OBJ:setOffset(math.floor(xInverted and oX+(-xAdd*n) or oX+xAdd*n), math.floor(yInverted and oY+(-yAdd*n) or oY+yAdd*n))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(animations, { f = f, t = time/frames})
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
textColoring = function(self, time, ...)
|
||||||
|
local colors = table.pack(...)
|
||||||
|
for n=1, #colors do
|
||||||
|
table.insert(animations, { f = function()
|
||||||
|
_OBJ:setForeground(colors[n])
|
||||||
|
end, t = time/#colors})
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
backgroundColoring = function(self, time, ...)
|
||||||
|
local colors = table.pack(...)
|
||||||
|
for n=1, #colors do
|
||||||
|
table.insert(animations, { f = function()
|
||||||
|
_OBJ:setBackground(colors[n])
|
||||||
|
end, t = time/#colors})
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
setText = function(self, time, text)
|
||||||
|
if(_OBJ.setText~=nil)then
|
||||||
|
for n=1, text:len() do
|
||||||
|
table.insert(animations, { f = function()
|
||||||
|
_OBJ:setText(text:sub(1,n))
|
||||||
|
end, t = time/text:len()})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
changeText = function(self, time, ...)
|
||||||
|
if(_OBJ.setText~=nil)then
|
||||||
|
local text = table.pack(...)
|
||||||
|
for n=1, #text do
|
||||||
|
table.insert(animations, { f = function()
|
||||||
|
_OBJ:setText(text[n])
|
||||||
|
end, t = time/#text})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
coloring = function(self, time, ...)
|
||||||
|
local colors = table.pack(...)
|
||||||
|
for n=1, #colors do
|
||||||
|
if(type(colors[n]=="table"))then
|
||||||
|
table.insert(animations, { f = function()
|
||||||
|
if(colors[n][1]~=nil)then
|
||||||
|
_OBJ:setBackground(colors[n][1])
|
||||||
|
end
|
||||||
|
if(colors[n][2]~=nil)then
|
||||||
|
_OBJ:setForeground(colors[n][2])
|
||||||
|
end
|
||||||
|
end, t = time/#colors})
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
wait = function(self, wait)
|
wait = function(self, wait)
|
||||||
nextWaitTimer = wait
|
nextWaitTimer = wait
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
rep = function(self, reps)
|
rep = function(self, reps)
|
||||||
for x = 1, reps do
|
for n = 1, reps do
|
||||||
table.insert(animations, { f = lastFunc, t = nextWaitTimer })
|
table.insert(animations, { f = lastFunc, t = nextWaitTimer })
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
@@ -61,10 +198,12 @@ return function(name)
|
|||||||
lastFunc = nil
|
lastFunc = nil
|
||||||
nextWaitTimer = 0
|
nextWaitTimer = 0
|
||||||
index = 1
|
index = 1
|
||||||
|
infinitePlay = false
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
play = function(self)
|
play = function(self, infinite)
|
||||||
|
infinitePlay = infinite and true or false
|
||||||
index = 1
|
index = 1
|
||||||
if (animations[index] ~= nil) then
|
if (animations[index] ~= nil) then
|
||||||
if (animations[index].t > 0) then
|
if (animations[index].t > 0) then
|
||||||
@@ -78,6 +217,7 @@ return function(name)
|
|||||||
|
|
||||||
cancel = function(self)
|
cancel = function(self)
|
||||||
os.cancelTimer(timerObj)
|
os.cancelTimer(timerObj)
|
||||||
|
infinitePlay = false
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -92,4 +232,4 @@ return function(name)
|
|||||||
object.__index = object
|
object.__index = object
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user