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).

Thanks in advance

  • \$\begingroup\$ What have you tried? Is there something that's specifically not working about Content.Load that you expected? \$\endgroup\$ Jun 1, 2014 at 23:17
  • \$\begingroup\$ 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. \$\endgroup\$
    – Daabri
    Jun 1, 2014 at 23:42

1 Answer 1


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

GameState currentGameState = GameState.TitleScreen;

Then just use a switch

        case GameState.TitleScreen:   
            //Load TitleScreen Stuff
       case GameState.Menu:
            //Load Menu Stuff
       case GameState.Level1:
            //Load Level 1 assets

            throw new Exception("Something Broke.");


You can then leverage the gamestates to cleanly handle your loading and unloading of game assets.

  • \$\begingroup\$ If you are going to use states why not use a state machine? \$\endgroup\$ Jun 2, 2014 at 15:31
  • \$\begingroup\$ This is very helpful! The most problem I had was recognising a good pattern for this. I made something similar like this before you answered, but this clear a lot up. I also need to dig deeper into basic XNA stuff I noticed, since I do not understand enums yet while they help tremendously. Thanks! \$\endgroup\$
    – Daabri
    Jun 9, 2014 at 15:12
  • \$\begingroup\$ This is a reasonable approach if your game is small, but it won't scale very well for large games since you'll need to update the switch statement every time you add a new level. A more flexible approach is to use a strategy pattern en.wikipedia.org/wiki/Strategy_pattern \$\endgroup\$ Jun 9, 2014 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .