public void SwitchState(SpaceInvaders pGame, GameStateManager.GameState nextState) { // Detach current state input observers pGame.DetachStateInputObservers(); // Queue any Time Events for later TimeEvent pTimeEvent = TimerManager.Pop(); while (pTimeEvent != null) { this.GetQueuedTimeEventManager().Enqueue(pTimeEvent.GetName(), pTimeEvent.GetCommand(), pTimeEvent.GetDeltaTime()); pTimeEvent = TimerManager.Pop(); } // Change game state pGame.SetGameState(nextState); // Load up TimerManager with next state's Time Events QueuedTimeEvent qte = pGame.GetStateQueuedTimeEventManager().Dequeue(); while (qte != null) { TimerManager.Add(qte.GetTimeEventName(), qte.GetCommand(), qte.GetTimeEventDelta()); // Get next queued event qte = pGame.GetStateQueuedTimeEventManager().Dequeue(); } // Attach next state input observers pGame.AttachStateInputObservers(); }