Skip to content

Commit ec2a41e

Browse files
committed
Animation ScrollText fix
1 parent 543d198 commit ec2a41e

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/plugins/animation.lua

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,34 @@ Animation.registerAnimation("fadeText", {
439439
Animation.registerAnimation("scrollText", {
440440
start = function(anim)
441441
anim.width = anim.element.get("width")
442-
anim.targetText = anim.args[2]
443-
anim.element.set(anim.args[1], "")
442+
anim.startText = anim.element.get(anim.args[1]) or ""
443+
anim.targetText = anim.args[2] or ""
444+
anim.startText = tostring(anim.startText)
445+
anim.targetText = tostring(anim.targetText)
444446
end,
445447

446448
update = function(anim, progress)
447-
local offset = math.floor(anim.width * (1-progress))
448-
local spaces = string.rep(" ", offset)
449-
anim.element.set(anim.args[1], spaces .. anim.targetText)
449+
local w = anim.width
450+
451+
if progress < 0.5 then
452+
local p = progress / 0.5
453+
local offset = math.floor(w * p)
454+
local visible = (anim.startText:sub(offset + 1) .. string.rep(" ", w)):sub(1, w)
455+
anim.element.set(anim.args[1], visible)
456+
else
457+
local p = (progress - 0.5) / 0.5
458+
local leftSpaces = math.floor(w * (1 - p))
459+
local incoming = string.rep(" ", leftSpaces) .. anim.targetText
460+
local visible = incoming:sub(1, w)
461+
anim.element.set(anim.args[1], visible)
462+
end
463+
450464
return progress >= 1
465+
end,
466+
467+
complete = function(anim)
468+
local final = (anim.targetText .. string.rep(" ", anim.width))
469+
anim.element.set(anim.args[1], final)
451470
end
452471
})
453472

0 commit comments

Comments
 (0)