Skip to content

Commit d2d5f8c

Browse files
committed
Added marquee animation
1 parent f61925d commit d2d5f8c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/plugins/animation.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,35 @@ Animation.registerAnimation("scrollText", {
470470
end
471471
})
472472

473+
Animation.registerAnimation("marquee", {
474+
start = function(anim)
475+
anim.width = anim.element.get("width")
476+
anim.text = tostring(anim.args[2] or "")
477+
anim.speed = tonumber(anim.args[3]) or 0.15
478+
anim.offset = 0
479+
anim.lastShift = -1
480+
anim.padded = anim.text .. string.rep(" ", anim.width)
481+
end,
482+
483+
update = function(anim, progress)
484+
local elapsed = os.epoch("local") / 1000 - anim.startTime
485+
local step = math.max(0.01, anim.speed)
486+
local shifts = math.floor(elapsed / step)
487+
if shifts ~= anim.lastShift then
488+
anim.lastShift = shifts
489+
local totalLen = #anim.padded
490+
local idx = (shifts % totalLen) + 1
491+
local doubled = anim.padded .. anim.padded
492+
local visible = doubled:sub(idx, idx + anim.width - 1)
493+
anim.element.set(anim.args[1], visible)
494+
end
495+
return false
496+
end,
497+
498+
complete = function(anim)
499+
end
500+
})
501+
473502
--- Adds additional methods for VisualElement when adding animation plugin
474503
--- @class VisualElement
475504
local VisualElement = {hooks={}}

0 commit comments

Comments
 (0)