HUD Item SlideIn

How can I make this alert slide in from the left ( it is 4 pixels from the left of the screen ) and stop when it is 4 pixels in like in the picture? I have seen a few threads but they are mostly examples of scrolling text and I can’t seem to get it to stop at a certain point.

[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]

http://www.darkflaw.com/images/slidein.png

[lua]local FarLeft = -WIDTH_OF_ALERT; – The width of the alert box
hook.Add(“HUDPaint”, “Scrolling Text”, function()
FarLeft = math.Clamp(FarLeft + FrameTime() * 5, -WIDTH_OF_ALERT, 4) – Increase 5 to make it faster
draw.DrawText(“Hello World”, “ScoreboardText”, FarLeft, 50, Color(255,255,255,255), 1);
end)[/lua]

Try this (obviously you need to adapt it for what you are trying to do).

[editline]09:06AM[/editline]

or this:

[lua]local FarLeft = 0;
hook.Add(“HUDPaint”, “Scrolling Text”, function()
FarLeft = FarLeft + (WIDTH_OF_BOX+4-FarLeft)*FrameTime()*5 - WIDTH_OF_BOX
draw.DrawText(“Hello World”, “ScoreboardText”, FarLeft, 50, Color(255,255,255,255), 1);
end) [/lua]

There are many ways you can do this. My favorite is:

[lua]current_pos = Lerp( FrameTime( ) * speed, current_pos, target_pos );[/lua]

Just set target_pos and it will go wherever you want. Also, the movement isn’t linear; it will slow down when nearing the target.