Latius
Hybrid Kart Mapper/Porter
I'm trying to make a ticker which would appear in the top right of the player's screen, and... Well, it's currently a bit jittery so far. In that while most of the time it smoothly scrolls from right to left as intended, sometimes it goes faster, slower or even reverses for a frame or two.
This is the current code I'm using:
Can someone help me out with finding where I've gone wrong, and how to fix it? I use the following call in the hud.add function:
This is the current code I'm using:
Code:
local function drawCroppedTicker(v, text, viewarea)
local frame = leveltime
local length = string.len(text)
local stringlen = 0
for a = 1, length do
local character = string.sub(text, a, a)
if character == " " or character == "!" or character == ","
or character == "." or character == "\"" then stringlen = $ + 4
elseif character == ":" or character == ";" or character == "`" then stringlen = $ + 5
elseif character == "|" then stringlen = $ + 3
else stringlen = $ + 8 end
end
frame = $ % stringlen
local croppedString = text .. text
local stringplace = 0
local stringstart = 0
local switch = false
local newlen = 1
for a = 1, length do
local character = string.sub(croppedString, a, a)
if character == " " or character == "!" or character == ","
or character == "." or character == "\"" then stringplace = $ + 4
elseif character == ":" or character == ";" or character == "`" then stringplace = $ + 5
elseif character == "|" then stringplace = $ + 3
else stringplace = $ + 8 end
if (not switch) and stringplace < frame then
croppedString = string.sub(croppedString, 2, string.len(croppedString))
stringstart = stringplace
elseif not switch then
switch = true
stringstart = frame - $
else
newlen = $ + 1
if stringplace > frame + viewarea + 20 then
croppedString = string.sub(croppedString, 1, newlen)
break
end
end
end
v.drawString(308 - viewarea - stringstart, 2, croppedString, V_SNAPTOTOP)
v.drawFill(300 - viewarea, 0, 10, 12, 233)
v.drawFill(310, 0, 10, 12, 233)
end
Can someone help me out with finding where I've gone wrong, and how to fix it? I use the following call in the hud.add function:
Code:
drawCroppedTicker(v, "Police Assault in Progress - ", 102)