protected GameState(Game game, GameStateManager manager) : base(game) { StateManager = manager; _childComponents = new List<GameComponent>(); _tag = this; }
/// <summary> /// Remove all other states and set a new state /// </summary> /// <param name="newState"></param> public void ChangeState(GameState newState) { while (_gameStates.Count > 0) RemoveState(); newState.DrawOrder = StartDrawOrder; _draworder = StartDrawOrder; AddState(newState); if (OnStateChange != null) OnStateChange(this, null); }
/// <summary> /// Add a new state /// </summary> /// <param name="newState"></param> public void PushState(GameState newState) { _draworder += DrawOrderInc; newState.DrawOrder = _draworder; AddState(newState); if (OnStateChange != null) OnStateChange(this, null); }
/// <summary> /// Helper for PushState(). /// </summary> /// <param name="newState"></param> private void AddState(GameState newState) { _gameStates.Push(newState); Game.Components.Add(newState); // Subscribe the state to OnStateChange. OnStateChange += newState.StateChange; }