Jump to content
  • Advertisement
Sign in to follow this  
Prog101

reduce oppacity problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!