fix AnimationNode state management
This commit is contained in:
parent
aecc9acde0
commit
de24808a82
@ -33,7 +33,7 @@ local easing = require "lib.utils.easing"
|
||||
--- @field duration number продолжительность в миллисекундах
|
||||
--- @field easing ease функция смягчения
|
||||
--- @field t number прогресс анимации
|
||||
--- @field finished boolean
|
||||
--- @field state "running" | "waiting" | "finished"
|
||||
local animation = {}
|
||||
animation.__index = animation
|
||||
|
||||
@ -41,7 +41,7 @@ animation.__index = animation
|
||||
function animation:bubbleUp()
|
||||
self.count = self.count - 1
|
||||
if self.count > 0 then return end
|
||||
self.finished = true
|
||||
self.state = "finished"
|
||||
if self.onEnd then self.onEnd() end
|
||||
if self.parent then self.parent:bubbleUp() end
|
||||
end
|
||||
@ -63,7 +63,7 @@ function animation:getValue()
|
||||
end
|
||||
|
||||
function animation:update(dt)
|
||||
if self.finished then return end
|
||||
if self.state ~= "running" then return end
|
||||
|
||||
if self.t < 1 then
|
||||
self.t = self.t + dt * 1000 / self.duration -- в знаменателе продолжительность анимации в секундах
|
||||
@ -82,14 +82,14 @@ local function new(data)
|
||||
end
|
||||
t.onEnd = data.onEnd
|
||||
t.count = 1 -- своя анимация
|
||||
t.finished = false
|
||||
t.children = {}
|
||||
t:chain(data.children or {})
|
||||
t.duration = data.duration or 1000
|
||||
t.easing = data.easing or easing.linear
|
||||
t.t = 0
|
||||
t.state = "running"
|
||||
t.finish = function()
|
||||
if t.finished then return end
|
||||
t.state = "waiting"
|
||||
t:bubbleUp()
|
||||
for _, anim in ipairs(t.children) do
|
||||
anim:run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user