Time for action – viewing the StarField in action
Add the following declaration to the Game1 class:
StarField starField;
In the declarations area of the Game1 class, temporarily modify the declaration for
gameState
fromGameStates.TitleScreen
toGameStates.Playing
:GameStates gameState = GameStates.Playing;
Update the
LoadContent()
method of the Game1 class to initialize thestarField
object. Be sure to place this code after thespriteSheet
texture is loaded.starField = new StarField( this.Window.ClientBounds.Width, this.Window.ClientBounds.Height, 200, new Vector2(0, 30f), spriteSheet, new Rectangle(0, 450, 2, 2));
In the
Upate()
method, add the following line to theGameStates.Playing
section of the switch statement you created earlier:starField.Update(gameTime);
In the
Draw()
method, change the background color fromColor.CornflowerBlue
toColor.Black
.Still in the
Draw()
method, add the following line to theif
block containingGameStates.Playing
:starField.Draw(spriteBatch...