Fade in & Fade out - Same rate for every clients?

Something came to mind,

I was writing a convenience function for fading in and fading out a color value ( not a whole color, simply one of it’s values ) and realised that, the value’s fade in and fade out rate was different for everyone and that for one reason, drawing speed ( FrameTime() ).

Here was the actual code I had:
[lua]function FadeInFadeOut( Start, End, Speed )

return math.Clamp( math.abs( Start - End ) * math.sin( CurTime() * Speed ) + ( 255 - Start ), Start, End )


It has been tested and proved to work smoothly, but unfortunatly, the speed set in will be different for everyone because of their FrameTime(), so I thought, how about I set a ratio using FrameTime(). Ex:

( Speed / FrameTime() ) * 100

That would make it so, people with a slower FrameTime() would get a faster Speed value, as opposite to those with a faster FrameTime(), they would get a slower speed value.

So far all this code and the ratio works perfectly once used in a draw event. The problem is, since I am using math.sin to make my value oscillate from low to high, the FrameTime() part, being inconsistant, comes in and ruins the smoothness of the fade.

Does someone have a way to do what I am trying to accomplish? Or possibly know if there is a work around inconsistant FrameTime()?

Thanks for taking the time.

( ps. If you test this function, Start is assumed to be a lesser value than End. )

FrameTime() is the distance a object moving at 1 pixel/second has moved in that frame. So if you want your speed to be the same for everybody multiply by FrameTime().

That dosen’t change anything, FrameTime() is an inconsistant value, think of it as FPS, slower your FPS, slower your draw time( FrameTime() ) so, it would still ruin the smoothness. Thanks for responding and trying tho.

And btw, FrameTime() is:

The time taken to render the last video frame clientside, or the delay between ticks serverside.

FrameTime() is not inconsistent, you use it to work out how much a variable should change in that frame/tick. IE
[lua]a = a + FrameTime() * 30[/lua]
That would increase the variable a at a rate of 30 units/second.

FrameTime() will output a value, it being the time taken to render a frame. The values I get are generally something along the lines of:


Using math.sin as said in the OP, with FrameTime() breaks the smoothness of the fade. When I say, FrameTime() being inconsistant, I mean outputing different values everytime.

Here is an example of what is happening.


Do you get where I am going?

If you are using CurTime you shouldn’t have to worry seeing how it’s synced with the server.

Use CurTime() not FrameTime()

Yah, CurTime will work better.

So CurTime() would be the solution to my problem?

The way I seen it is, since I am running the function in the draw hook, someone with a faster draw time would mean that the function gets executed faster, thus, making a faster fade in and fade out than some other clients. But now that I understand what you guys meant, everything is fine.

Thanks alot for the responses, case closed.