I am trying to make a point-and-click adventure game with XNA, starting off simple. My experience with XNA is about a month old now, know how the classes and inheritance works (basic stuff).

I have a problem where I cannot understand how I should load and unload the textures and game objects in the game, when the player transitions to another level. I've googled this >10 times, but all I find is hard coding while I don't even understand the basics of unloading yet.

All I want, is transitioning to another level (replacing all the sprites with new ones).

• What have you tried? Is there something that's specifically not working about Content.Load that you expected? – craftworkgames Jun 1 '14 at 23:17
• I have found this post, which I am using to try out stuff now. I don't understand half of it, I noticed. I think need to figure out how contentmanagers work and how to write my own. – Daabri Jun 1 '14 at 23:42

The way I handle level transitions is through game states. Let me give a little example:

Game states of: TitleScreen, Menu, Level1, Level2, Level3, Credits, Pause

So each game state can use it's own LoadContent and UnloadContent.

When TitleScreen is active, LoadContent loads a Title Image, then unloads them. When the Menu becomes active, it loads any graphics need with the menu, then unloads them. When Level1 becomes active, it loads all it's assets etc.

The only difference is a Pause game state, in which it doesn't load or unload, it just sits and doesn't call GameUpdate until the "unpause" is pressed.

How you manage gamestates is up to you. I like to create an enum named GameState

Something like this

public enum GameState
{
TitleScreen,
Level1,
Level2,
Level3,
Pause
};

GameState currentGameState = GameState.TitleScreen;


Then just use a switch

switch(this.gameState)
{
case GameState.TitleScreen:
break;
break;
case GameState.Level1:
//Load Level 1 assets
break;
//etc

default:
throw new Exception("Something Broke.");
break;

}