Monday, December 4, 2017

Creating A Blinking Text In Xna

Sometimes, just plain text is boring.
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.

Sumber http://aldokelvianto.blogspot.com

No comments:

Post a Comment

Laptop Graphic Terbaik Untuk Desain Grafis 2014

Mereview Laptop Desain Grafis tahun 2014 OPOSIP - Ketika saya bekerja dari rumah saya mempunyai sebuah PC yang didedikasikan yang sang...