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