26.09.2017, 14:16
Quote:
The easiest way is taking the color only (without transparency), eg:
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. |
PHP Code:
stock ShowPlayerObjective(playerid, color, string[], time)
{
PlayerTextDrawSetString(playerid, player_Textdraw[playerid][0], string);
PlayerTextDrawColor(playerid, player_Textdraw[playerid][0], color);
PlayerTextDrawShow(playerid, player_Textdraw[playerid][0]);
PlayerInfo[playerid][ptdTimer] = SetTimerEx("TextdrawFadeOut", 100, true, "ddds", playerid, color, time, string);
print("ShowPlayerObjective");
return 1;
}
public TextdtawFadeOut(playerid, color, time, string[])
{
PlayerInfo[playerid][ptdCount] += 100;
PlayerTextDrawColor(playerid, player_Textdraw[playerid][0], color + 255 - floatround(float(100) / float(time) * 255.0));
if(floatround((time / 100)) >= floatround(PlayerInfo[playerid][ptdCount]))
{
PlayerTextDrawHide(playerid, player_Textdraw[playerid][0]);
KillTimer(PlayerInfo[playerid][ptdTimer]);
}
return 1;
}
// EG
ShowPlayerObjective(playerid, 0x33AA3300, "Test my nigga", 4000);