Time for action – drawing the screen – the title screen
Modify the
Draw()
method of Game1 to include the code necessary to draw the game's title screen afterGraphicsDevice.Clear(Color.CornflowerBlue);
if (gameState == GameStates.TitleScreen) { spriteBatch.Begin(); spriteBatch.Draw(titleScreen, new Rectangle(0, 0, this.Window.ClientBounds.Width, this.Window.ClientBounds.Height), Color.White); spriteBatch.End(); }
Run the game and verify that the title screen is displayed. You will not be able to start the game however, as we haven't written the
Update()
method yet.Stop the game by pressing Alt + F4.
What just happened?
The title screen is drawn with a single call to the Draw()
method of the spriteBatch
object. Since the title screen will cover the entire display, a rectangle is created that is equal to the width and height of the game window.
The Draw() method – the play screen
Finally, we are ready to display the playing pieces on the screen...