Chapter 6. The State of Things

WHAT'S IN THIS CHAPTER?

  • Managing and tracking the state of your game

  • Handling transitions between game states

  • Detecting and handling phone hardware events

  • Understanding what happens when your game is interrupted by a call

  • Saving and restoring game state with local storage

A key part of game development is state management. This is how you handle the differences between the title screen and the middle of the game, as well as starting and ending your game, or even what goes on in the background while your game is paused.

When you receive an incoming phone call during your game, you don't just need to suspend game play and give control to the phone. You also must restore everything to the previous state when your player returns.

This chapter teaches you how to manage the state of your game and how to handle transitions between game states. You will also learn about detecting hardware events for the phone and how to use local storage to save and restore your game state.

GAME STATE

All video games go through various states as they run. Even the classic arcade machines used several states, such as running a demo in "attract" mode, the start screen displayed after you dropped in a quarter, an instructions screen, the actual game screen, and, of course, the high-score screen.

When designing a game, you must consider the various states and screens of your game before writing a single line of code. You need to know things like the following:

  • What screens are displayed, ...

Get Professional Windows® Phone 7 Game Development: Creating Games using XNA Game Studio 4 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.