public GameState(Game game, GameStateManager manager) : base(game) { this.stateManager = manager; this.childComponents = new List<GameComponent>(); this.tag = this; }
/// <summary> Used to move to another state and keep the previous state in stack </summary> public void PushState(GameState newState) { this.drawOrder += DrawOrderInc; newState.DrawOrder = this.drawOrder; this.AddState(newState); if (this.onStateChange != null) { this.onStateChange(this, null); } }
/// <summary> Removes all other states from stack except the specified one. </summary> public void ChangeState(GameState newState) { while (this.gameStates.Count > 0) { this.RemoveState(); } newState.DrawOrder = StartDrawOrder; this.drawOrder = StartDrawOrder; this.AddState(newState); if (this.onStateChange != null) { this.onStateChange(this, null); } }
/// <summary> Adds a state to the stack and subscribes it to the event. </summary> private void AddState(GameState newState) { this.gameStates.Push(newState); Game.Components.Add(newState); this.onStateChange += newState.StateChange; }