How To: Manage Player Movement Between Lobby and Gameplay Modes
Managing Player Movement Between Modes
To manage player movement between lobby and gameplay modes
Hook up the session state change events.
The NetworkSession.GameStarted event indicates that all players have moved from the lobby to gameplay. The NetworkSession.GameEnded event occurs when the players move from gameplay back to the lobby. NetworkSession.SessionEnded occurs when the session is over, and all players move from the lobby of a session back to find another available session.
Use NetworkGamer.IsReady to signal that a player is ready to move from the lobby to the game.
On the host gaming machine, check NetworkSession.IsEveryoneReady to see if all players are ready.
If this is true, call NetworkSession.StartGame to change the game state from the lobby to gameplay mode.
In the NetworkSession.GameStarted event handler, make preparations for the game to begin.
In this example, the game object states are reset for the new game.
In the NetworkSession.GameEnded event handler, make preparations to return the players to the lobby, such as recording the high score.
In the NetworkSession.SessionEnded event handler, return to the game title screen.
Note that before the session ends, the session can move between lobby and gameplay states as many times as the player wants. To retrieve the session state at any time, you can check the NetworkSession.SessionState property.