Adding lua scripts

This commit is contained in:
Don Honerbrink
2015-12-11 16:17:23 -06:00
parent a1c5b78dd2
commit b3f5b89b04
5 changed files with 379 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
event = require(Event)
tween = require(Tween)
local Animate = {}
Animate.__index = Animate
function Animate.new()
instance = {
component = nil,
loop = false,
animationIndex,
elapsedTime = 0
startInfo = {}
animations = []
}
setmetatable(instance, Animate)
event.register("update", Animate, Animate.update)
return instance
end
function Animate.add(time, tweenInfo)
self.animations[#self.animations+1] = {duration=time, info=tweenInfo}
end
function Animate:start(component, loop)
self.component = component
self.loop = loop
self.elapsedTime = 0
self.startInfo = component:getProperties()
end
end
function Animate:update(dt)
if self.animationIndex > #self.animations and not self.loop then
return
end
self.elapsedTime = self.elapsedTime + dt
animation = self.animations[animationIndex]
if animation.duration > self.elapsedTime then
self.animationIndex = self.animationIndex + 1
self.elapsedTime = 0
self.startInfo = component:getProperties()
if self.animationIndex > #self.animations and self.loop then
self.animationIndex = 0
end
end
curr = {
x = tween.calculate(animation.x, startInfo.x, duration, elapsedTime),
y = tween.calculate(animation.y, startInfo.y, duration, elapsedTime),
width = tween.calculate(animation.width, startInfo.width, duration, elapsedTime),
height = tween.calculate(animation.height, startInfo.height, duration, elapsedTime),
transparency = tween.calculate(animation.transparency, startInfo.transparency, duration, elapsedTime),
rotate = Tween.calculate(animation.rotate, startInfo.rotate, duration, elapsedTime)
}
component.setPosition(componentId, curr.x, curr.y)
component.setDimensions(componentId, curr.width, curr.height)
component.setTransparency(componentId, curr.transparency)
component.setRotate(componentId, curr.rotate)
end
return Animate