Fading text for draw.WordBox() ?

I want to make text that fades into the background after time.
Is it possible to make a timer to change the alpha to 0 over time?

For example :

local AlphaTime = 255
timer.Create("tester", 1,51, function() AlphaTime = (AlphaTime - 5)

function GM:HUDPaint()

    draw.DrawText("Hello World", "Default", ScrW() / 2 - 70, ScrH() - 63, Color(255, 255, 255, AlphaTime),TEXT_ALIGN_CENTER)

use CurTime, i know i didnt explain well ill probably edit this post later

I’ll have to experiment with CurTime.

Do it inside of HUDPaint. Don’t use a timer to fade. What’s the purpose for the text and it can be tailored to fit whatever need.

I have fading text set up for doors, ie the closer you are the brighter it is, the further away the dimmer it becomes until it’s nothing. Same for players, etc.

You can tie Alpha to a function, a function over time, distance, or whatever…

I was playing around with the thought of EXP being displayed for a short while then faded out.

I’ll probably use functions but i’m stilling thinking about the idea.

[editline]21st March 2014[/editline]

Should the function be inside or outside the script, does it matter?

I do something similar to that; on key press, display something for a short time then fade out.

The function can be anywhere; you could make a generic one, but if you’re doing a time-based I’d just recommend using Lerp to create the fraction * 255 for the alpha.

Add me on Steam; I have an Arma style quick-command menu that I’m not using in my game-mode where parts may help you. If you message me, I’ll cut out the parts for fade-in/out.

Simple fading text from Garry’s Animation system for Panels:

local Fraction = math.TimeFraction( anim.StartTime, anim.EndTime, systime )
Fraction = math.Clamp( Fraction, 0, 1 )