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); ...
Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.