/// <summary> /// Add a new state to the container. /// if the satte is the first, which will be added to the /// list then this state becomes the current state. /// </summary> /// <param name="state">the state to add</param> public void AddState(BasicGameState state) { state.Init(this); if (currentState == null) { currentState = state; currentState.Enter(this); } states.Add(state.GetStateID(), state); }
/// <summary> /// Called for updates. /// </summary> /// <param name="gameTime"> the game time of the current context</param> protected override void Update(GameTime gameTime) { // if (SwitchingStates) { if (SwitchTimer <= 0) { if (!SwitchType) { currentState = nextState; currentState.Enter(this); SwitchType = true; SwitchTimer = 1000; } else SwitchingStates = false; } else SwitchTimer -= gameTime.ElapsedGameTime.Milliseconds; } else { currentState.Update(gameTime, this); } base.Update(gameTime); }