help with scrolling title

help with scrolling title

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

help with scrolling title

Post by Funkencool »

So if you've played BAR you might have noticed the scrolling song titles in the upper right hand corner. Now, I'm looking for a better way to implement them than how it is currently.

Code: Select all

local function scrollName()
    local length = string.len(trackLabel)
    if length > 35 then
        if labelVar > length then labelVar = 0 end
        songLabel:SetCaption(string.sub(trackLabel, labelVar)..string.sub(trackLabel,0, labelVar-1))
        labelVar = labelVar + 1
    end
end
As you can see it's quite hacky and horribly inefficient; lua has to create a new string, the length of the string, for every char in the string as it mashes the two halves together.

What I'd like to do is draw the title twice, one slightly after the other and move them slowly to the left while clipping them to within the parent chili window. I feel like this would be easy if I knew anything about drawing fonts but I don't, so any advice?
Last edited by Funkencool on 02 Apr 2016, 13:44, edited 1 time in total.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: help with scrolling title

Post by Kloot »

gl.Font.Print + gl.RenderToTexture + gl.Scissor + gl.Translate
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: help with scrolling title

Post by Funkencool »

I looked more thoroughly into it and any performance impact is very negligible, but I'd still like something with more consistent results so I'll take your snippet and head to wiki!
Post Reply

Return to “Lua Scripts”