26.09.2017, 13:54
The easiest way is taking the color only (without transparency), eg:
the last two digits are the Alpha channel, which is ranging from 0x00 to 0xFF (0 - 255). That means you can just add a value from 0 to 255 to the base color, 0 being invisible and 255 being completely visible.
For a fade in/out to take 5000 ms you can do the following calculation for the color:
Fade in:
Fade out:
In this example 5000 is the total time, 1250 is the time in ms that had already passed.
Using float for the calculation is important here, since 1250 / 5000 would be zero if calculated as integer values. floatround will then convert it to an integer value.
Make sure that the time passed is never higher than the time it should take in total, otherwise it will screw up the color as adding 256 to 0xFF33CC00 would change the Blue color channel.
You can use the SetAlpha function Skream suggested too, but it doesn't make a difference in this example.
Code:
0xFF33CC00
For a fade in/out to take 5000 ms you can do the following calculation for the color:
Fade in:
Code:
PlayerTextDrawColor(playerid, player_TextDraw[playerid][0], 0xFF33CC00 + floatround(float(1250) / float(5000) * 255.0));
Code:
PlayerTextDrawColor(playerid, player_TextDraw[playerid][0], 0xFF33CC00 + 255 - floatround(float(1250) / float(5000) * 255.0));
Using float for the calculation is important here, since 1250 / 5000 would be zero if calculated as integer values. floatround will then convert it to an integer value.
Make sure that the time passed is never higher than the time it should take in total, otherwise it will screw up the color as adding 256 to 0xFF33CC00 would change the Blue color channel.
You can use the SetAlpha function Skream suggested too, but it doesn't make a difference in this example.