How would you actively change the coordinates of text drawn though draw.DrawText? More specifically I'm trying to make the text scroll across the screen from left to right. I tried the following:
[lua]
function GM:HUDPaint()
FarLeft = FarLeft + 1
draw.DrawText("Hello World", "ScoreboardText", FarLeft, 50, Color(255,255,255,255),1)
end
[/lua]
The best way is making your own vgui element like so: [b][url=wiki.garrysmod.com/?title=Vgui.Register]Vgui.Register [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=iRzilla;19339424]You would calculate where you want it to draw and then use the cords.[/QUOTE]
Can you explain that a bit more? I'm not sure what your saying.
Exactly that, you alter the set of coordinates you want it to draw at.
[lua]
myHUDCoord = 5
myHUDVelocity = 1
local function myHUDThink()
--make it change direction if it's out of bounds
if myHUDCoord > 500 then
myHUDVelocity = -1
end
if myHUDCoord < 5 then
myHUDVelocity = 1
end
myHUDCoord = myHUDCoord + myHUDVelocity*FrameTime()
end
hook.Add("Think", "myHUDThink", myHUDThink)
local function myHUDPaint()
draw.DrawText("Wello Horld", "ScoreboardText", myHUDCoord, 50, Color(255,255,255,255),1)
end
hook.Add("HUDPaint", "myHUDPaint", myHUDPaint)
[/lua]
Untested but in theory it moves slowly between 5 and 500
What you are doing in your first post is nearly correct, you just need to declare FarLeft before the hook to 0.
[lua]local FarLeft = 0;
hook.Add("HUDPaint", "Scrolling Text", function()
FarLeft = (FarLeft + ScrW()/8 * FrameTime()) % ScrW();
draw.DrawText("Hello World", "ScoreboardText", FarLeft, 50, Color(255,255,255,255),1);
end)[/lua]
That will scroll the text across the screen every 8 seconds and wrap it so it starts again from the left when it reaches the end of the screen.
Lol i was defining it in the hook, wow xD thanks a lot guys.
Sorry, you need to Log In to post a reply to this thread.