X hits on this document

345 views

0 shares

0 downloads

0 comments

40 / 102

{

   ScreenManager.SpriteBatch.DrawString(font, text,

       new Vector2(position.X + 1, position.Y + 1), Color.Black);

   ScreenManager.SpriteBatch.DrawString(font, text, position, color);

}

// A simple helper to draw shadowed text.

void DrawString(SpriteFont font, string text, Vector2 position, Color color, float fontScale)

{

   ScreenManager.SpriteBatch.DrawString(font, text,

       new Vector2(position.X + 1, position.Y + 1),

       Color.Black, 0, new Vector2(0, font.LineSpacing / 2),

       fontScale, SpriteEffects.None, 0);

   ScreenManager.SpriteBatch.DrawString(font, text, position,

       color, 0, new Vector2(0, font.LineSpacing / 2),

       fontScale, SpriteEffects.None, 0);

}

The above helper methods draw shadowed text by drawing two instances of a specified string, one colored black and with a slight offset from the other. The second variation of the method allows scaling of the written text.

93.

Change GameplayScreen’s Draw method by uncommenting the call to the DrawHud method. The method should now look like this:

C#

public override void Draw(GameTime gameTime)

{

   ScreenManager.SpriteBatch.Begin();

   // Render all parts of the screen

   DrawBackground();

   // DrawComputer(gameTime);

   // DrawPlayer(gameTime);

   DrawHud();

   ScreenManager.SpriteBatch.End();

}

94.

Add the DrawHud method:

C#

void DrawHud()

{

   if (gameOver)

   {

       Texture2D texture;

       if (player.Score > computer.Score)

       {

           texture = victoryTexture;

Page | 40

Document info
Document views345
Page views345
Page last viewedThu Jan 19 13:14:04 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments