Hey,
I've been messing around with integrating several different pieces from the sample projects together, but I've run into an issue when trying to get a Graphics sample working correctly when switching from it back to a menu game state. I've actually got the sample loading up and running perfectly when you hit the start button on the menu, but it's when I return to the menu from the game where the issue occurs.
When I start the game, I add the level component to the game and then set the visibility of the UI component to false so it won't cover up the game, but will still receive update calls. Once I hit escape and return back to the main menu, I set the visibility and enabled properties for my Graphics level to false and then re-enable the visibility of the UI component.
This all works great for about half a second (the menu shows up), but then the game crashes. The graphics are still trying to draw things in the component even they they are "disposed" according to the exception. What's the best way to handle stopping a component using digital rune's graphics? Is there a property that will tell the screen to stop trying to draw until I want it to start again? I tried removing the component, disposing it, and just couldn't find a way that doesn't throw this exception. Any ideas at all would be greatly appreciated
Here's the code I'm using to go between the game states:
/// <summary>
/// Called when "Game" state is entered.
/// </summary>
private void OnEnterGameScreen(object sender, StateEventArgs eventArgs)
{
if (level == null)
{
level = new Level01(Game);
Game.Components.Add(level);
}
else
{
_inputService.EnableMouseCentering = true;
level.Enabled = true;
level.Visible = true;
}
this.Visible = false;
Game.IsMouseVisible = false;
}
/// <summary>
/// Called every frame when "Game" state is active.
/// </summary>
private void OnUpdateGameScreen(object sender, StateEventArgs eventArgs)
{
// Exit the "Game" state if Back button or Escape key is pressed.
if (_inputService.IsPressed(Buttons.Back, false, LogicalPlayerIndex.One)
|| _inputService.IsPressed(Keys.Escape, false))
{
_stateMachine.States.ActiveState.Transitions["GameToMenu"].Fire();
}
}
/// <summary>
/// Called when "Game" state is exited.
/// </summary>
private void OnExitGameScreen(object sender, StateEventArgs eventArgs)
{
this.Visible = true;
level.Visible = false;
level.Enabled = false;
_inputService.EnableMouseCentering = false;
Game.IsMouseVisible = true;
}