Time for action – viewing the StarField in action

  1. Add the following declaration to the Game1 class:
    StarField starField;
  2. In the declarations area of the Game1 class, temporarily modify the declaration for gameState from GameStates.TitleScreen to GameStates.Playing:
    GameStates gameState = GameStates.Playing;
  3. Update the LoadContent() method of the Game1 class to initialize the starField object. Be sure to place this code after the spriteSheet 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));
  4. In the Upate() method, add the following line to the GameStates.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.