You want something fancier, like ..Fading text!
Well.. not that exciting. But you get the idea.
So, how to do that?
I assume you've already understand how to use spriteFont,
After you've created spriteFont and about to draw it to the screen using DrawString method, use DrawString parameter which is use R,G,B,A rather than predefined Color. Like this :
This allow you to customize color and of course.. Alpha blending.
Update the variable in Update method as you like.
public override void Draw( GameTime gameTime)
{
spriteBatch.Begin();
spriteBatch.DrawString(yourSpriteFont, stringnya, posisi,
new Color (0,0,0,i));
spriteBatch.End();
base.Draw(gameTime);
}
public override void Update( GameTime gameTime)
{
switch (color) {
case 0 :
i += 5;
if (i == 255)
color = 1;
break;
case 1 :
i -= 5;
if (i == 0)
color = 0;
break;
}
}
You can also customize Color and fade depends on time using gameTime.ElapsedGameTime.Milliseconds if you want.
No comments:
Post a Comment