EDIT: After creating the post below it has come to my attention that the error was actually created when I destroyed the spriteBatch object and re-created it. In fact, the spriteBatch object should not be released/disposed of at all during the lifetime of the game.
Greetings all, PiscesMike here.
Wanted to set out the goals for the end of this week (Friday). As mentioned earlier, I plan to have the animated sprite class up sometime Wednesday. Before getting that up though I really wanted to track down the issue with the screen contents disappearing randomly. So, after a good amount of time spent on that today, I finally got it resolved. I'll get into that in a little bit. For the time being, a couple of things I want to change and/or add to the code before we go farther needs to be addressed.
Our goal for this exercise is to complete an entire game. Taking that into consideration I've come to the conclusion that the game should include an opening title screen as well as a credits screen, and high score display. Considering what we've already got done on the code, and thanks to the fact I solved the issue with the screen contents disappearing, I think these are achievable goals within the time frame. Actually, once the 'animated sprite' class is implemented, I think things will move along pretty quickly. This does add some complexity to the game overall, but I have a solution I think is elegant and should work well, and wanted to get things out there going forward. Quite frankly, this particular issue should have been taken care of before getting to this point and it is never good to add or try and make major changes this far into development. However, we are on a learning curve and I think these will be a couple of features that will pay off in this case. In addition, we will be building off mostly existing code so we can think of this as added functionality instead of a complete re-write. I suppose in the real world, expecting the Game1.cs class to be static and unchanging isn't something that happens often, and this is no exception.
So, I plan to implement the differing game screens using game states, sometimes referred to as render states. With each of these game states we will encapsulate everything that we expect to be rendered on screen, as well as reacting to user input, playing the music/sound effects for the particular screen, and chaining to other game states when needed. (For example, once the user presses start, we transition from the 'title screen' game state to the 'game play' game state.). Keep this in mind for Wednesday updates, as an early version may be included.
As to the error in the current code, it was actually something that was entirely my fault. I'm still new to C, and C# in specific, and this is one of those things that slip by new programmers, but really shouldn't. I created an error in the garbage collection function in the Game1.cs class called ResetGame(). In this routine, I prepare the app for a restart by setting all of the objects to null. Normally this would work great, however we are in the world of XNA, and setting something to null doesn't always do what we expect. In this case, the spriteBatch object is not released correctly when set to null. You must call the objects Dispose method. So the line in the ResetGame() function that reads:
should, in fact, read:
"May the mercy of His Divine Shadow fall upon you." - Stanley H. Tweedle, Security Guard class IV, The League of 20,000 planets