new
Text: WholeScreen;
// The "Text:" tag defines the variable as a TextDraw, imagine that.
new
ScreenStatus [ MAX_PLAYERS ] = 0,
// "ScreenStatus" is the opacity of the fade.
FadeTDTimer [ MAX_PLAYERS ] = -1;
// "FadeTDTimer" is just the timer which we can kill after the players screen is done fading.
public OnGameModeInit ( )
{
WholeScreen = TextDrawCreate( -20.000000, 0.000000, "_" );
// This creates a TextDraw which covers the entire screen.
TextDrawUseBox( WholeScreen, 1 );
TextDrawBoxColor( WholeScreen, 0x000000FF );
// This creates a pure-black box over the entire TextDraw (which, remember, covers your entire screen..)
TextDrawAlignment( WholeScreen, 0 );
// We don't use Alignment, so let's set it to zero just to make sure it doesn't bug out.
TextDrawBackgroundColor( WholeScreen, 0x000000FF );
// Let's set the background color to black too!
TextDrawFont( WholeScreen, 3 );
// I just picked a random font for this, although the font isn't important at all.
TextDrawLetterSize( WholeScreen, 1.000000, 52.200000 );
// TextDrawLetterSize with a box enabled modifies the Y height of the TextDraw.
TextDrawColor( WholeScreen, 0x000000FF );
// TextDrawColor modifies the color of the TextDraw, imagine that!
//The rest of your code OnGameModeInit.
return true;
}
CMD:fade( playerid, params[] )
{
if( ScreenStatus [ playerid ] == 0 )
{
// If their ScreenStatus is 0, that means a fade is currently not active.
ScreenStatus [ playerid ] = 1;
// This sets their ScreenStatus to 1, which means that as long as it's not 0, their screen is fading.
TextDrawShowForPlayer( playerid, WholeScreen );
// We obviously have to show the TextDraw we want to fade..
FadeTDTimer [ playerid ] = SetTimerEx( "FadeTextdraw", 50, true, "i", playerid );
// We assign the ID of the timer to "FadeTDTimer [ playerid ]", which is one of our player-variables!
// SetTimerEx is just a timer which passes an argument. In this case it's our ID, which is an integer ("playerid")
}
else return SendClientMessage( playerid, -1, "You are already fading!" );
return true;
}
forward FadeTextdraw( playerid );
public FadeTextdraw ( playerid )
{
switch( ScreenStatus [ playerid ] ) // This is faster than an 'if statement'
{
case 1:
{
TextDrawBoxColor( WholeScreen, 0x000000EE );
// EE is one of the Alpha Values of a HEX Color!
}
case 2:
{
TextDrawBoxColor( WholeScreen, 0x000000DD );
// DD is less visible than EE, but more visible than CC.
}
case 3:
{
TextDrawBoxColor( WholeScreen, 0x000000CC );
// CC is less visible than DD, but more visible than BB.
}
case 4:
{
TextDrawBoxColor( WholeScreen, 0x000000BB );
// BB is less visible than CC, but more visible than AA.
}
case 5:
{
TextDrawBoxColor( WholeScreen, 0x000000AA );
// AA is less visible than BB, but more visible than 99.
}
case 6:
{
TextDrawBoxColor( WholeScreen, 0x00000099 );
// 99 is less visible than AA, but more visible than 88.
}
case 7:
{
TextDrawBoxColor( WholeScreen, 0x00000088 );
// 88 is less visible than 99, but more visible than 77.
}
case 8:
{
TextDrawBoxColor( WholeScreen, 0x00000077 );
// 77 is less visible than 88, but more visible than 66.
}
case 9:
{
TextDrawBoxColor( WholeScreen, 0x00000066 );
// 66 is less viisble than 77, but more visible than 55.
}
case 10:
{
TextDrawBoxColor( WholeScreen, 0x00000055 );
// 55 is less visible than 66, but more visible than 44.
}
case 11:
{
TextDrawBoxColor( WholeScreen, 0x00000044 );
// 44 is less visible than 55, but more visible than 33.
}
case 12:
{
TextDrawBoxColor( WholeScreen, 0x00000033 );
// 33 is less visible than 44, but more visible than 22.
}
case 13:
{
TextDrawBoxColor( WholeScreen, 0x00000022 );
// 22 is less visible than 33, but more visible than 11.
}
case 14:
{
TextDrawBoxColor( WholeScreen, 0x00000011 );
// 11 is less visible than 22, and 00 is completely transparent.
}
case 15:
{
TextDrawBoxColor( WholeScreen, 0x00000000 );
// This makes the TextDraw completely transparent.
KillTimer( FadeTDTimer [ playerid ] );
// Remember to kill the Timer, otherwise you will have a constant 50 millisecond timer running.
TextDrawHideForPlayer( playerid, WholeScreen );
// Hide the transparent TextDraw.
ScreenStatus [ playerid ] = 0;
// Reset their Status to 0, because they're no longer fading.
return true;
}
}
TextDrawHideForPlayer( playerid, WholeScreen );
TextDrawShowForPlayer( playerid, WholeScreen );
return ScreenStatus [ playerid ] ++;
// Every time the function is called, the TextDraw is refreshed (Hidden & then re-shown and their ScreenStatus goes up 1.
}
Very nicely explained good job, i hope every tutorial was like this.
|
Also works even in other colors?
Without editing the TextDrawBoxColors? Btw. Nice. |
There is a much simpler way to do that switch by calculating the TD colour, and thus also supporting other colours. Check y_zonepulse for an example of slowly fading between two arbitrary colours in arbitrary time. I'd suggest also checking seiffade, but I'm not sure how that one works.
|
I saw that, I was simply pointing you to a place where information on a simpler method was available.
|