SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/09/2017, 12:51 PM   #1
JaKe Elite
High-roller
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,684
Reputation: 484
Default Color Transparency

How do I change a color transparency, applying a fade in/out effect?

E.G.:
I have 0x33AA33FF which is color green, it will slowly fade out making the alpha value FF change to 99 and then so on until it become zero which is invisible/transparent. (vice-versa)
__________________


making a comeback soon
JaKe Elite is offline   Reply With Quote
Old 26/09/2017, 12:53 PM   #2
Skream
Banned
 
Join Date: Apr 2012
Posts: 225
Reputation: 64
Default Re: Color Transparency

just decrease and set the alpha
Skream is offline   Reply With Quote
Old 26/09/2017, 12:55 PM   #3
JaKe Elite
High-roller
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,684
Reputation: 484
Default Re: Color Transparency

Quote:
Originally Posted by Skream View Post
just decrease and set the alpha
How?

(color - 0x99) ??
__________________


making a comeback soon
JaKe Elite is offline   Reply With Quote
Old 26/09/2017, 12:55 PM   #4
GustavoKarasek
Big Clucker
 
GustavoKarasek's Avatar
 
Join Date: Aug 2017
Posts: 76
Reputation: 9
Default Re: Color Transparency

http://forum.sa-mp.com/showthread.php?t=422245
__________________
Code:
* Mapeamentos
[Map] Base Militar #1 - 100%
Concluído - Parado - Em desenvolvimento
GustavoKarasek is offline   Reply With Quote
Old 26/09/2017, 12:57 PM   #5
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,194
Reputation: 326
Default Re: Color Transparency

PHP Code:
((color 0xFFFFFF00) | (alpha 0xFF)) 
AbyssMorgan is offline   Reply With Quote
Old 26/09/2017, 12:57 PM   #6
Skream
Banned
 
Join Date: Apr 2012
Posts: 225
Reputation: 64
Default Re: Color Transparency

Quote:
Originally Posted by JaKe Elite View Post
How?

(color - 0x99) ??

pawn Code:
#define SetAlpha(%0,%1)              (((%0) & 0xFFFFFF00) | ((%1) & 0xFF))

pawn Code:
SetAlpha(color, 0x30) // 2 - alpha
Skream is offline   Reply With Quote
Old 26/09/2017, 01:11 PM   #7
JaKe Elite
High-roller
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,684
Reputation: 484
Default Re: Color Transparency

Ahh thank you, I will try that out cheers!
__________________


making a comeback soon
JaKe Elite is offline   Reply With Quote
Old 26/09/2017, 01:18 PM   #8
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 293
Reputation: 128
Default Re: Color Transparency

PHP Code:
while (color 0xFF) --color
OneDay is offline   Reply With Quote
Old 26/09/2017, 01:25 PM   #9
JaKe Elite
High-roller
 
Join Date: Apr 2012
Location: Philippines
Posts: 3,684
Reputation: 484
Default Re: Color Transparency

Alright now with all of those stuffs setted up, I have no idea on how will I do the fade in/out effect but I have already setted up the function & the timer.

PHP Code:
stock ShowPlayerObjective(playeridcolorstring[], time)
{
    
PlayerTextDrawSetString(playeridplayer_Textdraw[playerid][0], string);
    
PlayerTextDrawColor(playeridplayer_Textdraw[playerid][0], color);
    
PlayerTextDrawShow(playeridplayer_Textdraw[playerid][0]);
    
PlayerInfo[playerid][ptdTimer] = SetTimerEx("TextdrawFadeOut"100true"ddds"playeridcolortimestring);
    return 
1;
}

public 
TextdtawFadeOut(playeridcolortimestring[])
{
    
PlayerInfo[playerid][ptdCount] += 1000;


__________________


making a comeback soon
JaKe Elite is offline   Reply With Quote
Old 26/09/2017, 01:54 PM   #10
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,591
Reputation: 528
Default Re: Color Transparency

The easiest way is taking the color only (without transparency), eg:

Code:
0xFF33CC00
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:

Code:
PlayerTextDrawColor(playerid, player_TextDraw[playerid][0], 0xFF33CC00 + floatround(float(1250) / float(5000) * 255.0));
Fade out:

Code:
PlayerTextDrawColor(playerid, player_TextDraw[playerid][0], 0xFF33CC00 + 255 - floatround(float(1250) / float(5000) * 255.0));
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.
NaS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing color transparency Darkwood17 Scripting Help 2 29/06/2015 07:13 PM
Is there any function to change some color transparency Magic_Time Scripting Help 3 01/09/2014 05:05 AM
how to make color more transparency jame42 Help Archive 4 30/03/2011 09:30 AM
Change transparency of a players color. pyrodave Help Archive 5 14/10/2009 05:22 PM
Color Transparency Dujma Help Archive 7 19/03/2009 01:38 PM


All times are GMT. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.