# reduce oppacity problem

This topic is 3964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

/*how can i reduce the oppacity from 255 to 0 over the variable time*/
for (i = 0; i < NbCreditsInList; i++)
{
int time  = gGameTime - cList.StartTime;
if (time <= 5000)
{
int oppacitcy = ?;

sprintf(creditString,"%s %d", STRING(ST_CREDIT_RESPECT + cList.Type) ,cList.Score);
BjTextPrint(creditString, Xpos,Ypos, BJColourMake(255, 255, 255, oppacitcy), FONT_CHALK, TJ_CENTREXY);
Ypos+=yOffset;
}
else
{
cList.Type = -1;
cList.StartTime = 0;
cList.Score = 0;
}
}


[Edited by - Prog101 on February 5, 2008 9:37:17 AM]

##### Share on other sites
Do a search for linear interpolation.

Essentially:

x = x0 + t(x1 - x0)

where x is the current value (opacity in your case), x0 is the initial value, x1 is the final value and t is the percentage of the way it is from x0 to x1.

For instance, if you want to fade out from 255 to 0 in 3 seconds, you'll get the current opacity by subbing in x0 = 255, x1 = 0, t = current elapsed time / 3 seconds.

I'll leave it to you to convert this to code.

Essentially this equation works when interpolating anything (i.e. points, colours, etc.) although the interpolation is always linear, which means that the speed of the fade is consistent the whole way through. There are other types of interpolation you could search for if you were interested.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013450
×