diff --git a/lib/animation_node.lua b/lib/animation_node.lua index 8f560f3..b8309e7 100644 --- a/lib/animation_node.lua +++ b/lib/animation_node.lua @@ -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()