feat(tweenmanager): add a switch system
This commit is contained in:
parent
fcd1288ebf
commit
6418b77b39
1 changed files with 27 additions and 1 deletions
|
@ -7,7 +7,7 @@ function TweenManager:new(subject)
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
|
|
||||||
self.tweens = {}
|
self.tweens = {}
|
||||||
self.targets = {}
|
self.switches = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function TweenManager:newTween(start, duration, target, easing)
|
function TweenManager:newTween(start, duration, target, easing)
|
||||||
|
@ -20,6 +20,16 @@ function TweenManager:newTween(start, duration, target, easing)
|
||||||
table.insert(self.tweens, newTween)
|
table.insert(self.tweens, newTween)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TweenManager:newSwitch(start, bools)
|
||||||
|
local newSwitch = {}
|
||||||
|
-- we add the data into a tween wrapper
|
||||||
|
newSwitch.bools = bools
|
||||||
|
newSwitch.start = self.timer + start -- /!\ START IS RELATIVE TO CURRENT TIME
|
||||||
|
newSwitch.clear = newSwitch.start + 1
|
||||||
|
|
||||||
|
table.insert(self.switches, newSwitch)
|
||||||
|
end
|
||||||
|
|
||||||
function TweenManager:update(dt)
|
function TweenManager:update(dt)
|
||||||
self.timer = self.timer + dt
|
self.timer = self.timer + dt
|
||||||
|
|
||||||
|
@ -29,6 +39,22 @@ function TweenManager:update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i, switch in ipairs(self.switches) do
|
||||||
|
if (self.timer > switch.start) then
|
||||||
|
-- We test each boolean in the switch
|
||||||
|
for i, bool in ipairs(switch.bools) do
|
||||||
|
-- if it's nil, we set it to true
|
||||||
|
if self.subject[bool] == nil then
|
||||||
|
self.subject[bool] = true
|
||||||
|
else
|
||||||
|
-- if it's not nil, we reverse the boolean
|
||||||
|
self.subject[bool] = (self.subject[bool] == false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.remove(self.switches, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:clearEndedTweens()
|
self:clearEndedTweens()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue