Mixing the Game State Management and Platformer XNA Recipes

Sign in to queue


Just about every application needs some kind of state management, games more so than most. From basic menus, to options, to "life" management. A game without options, lives, etc. is only half a game.

The App Hub provides two, among many others, interesting recipes. One for a basic game, Platformer "... is a self-contained game solution for Windows, Xbox 360, and Windows Phone 7 that includes both game code and game assets. The game is a standard 2D platformer with levels, enemies, and collectable gems." and one for Game State Management, "...shows how to manage the transitions among menus and gameplay states." While each is useful by themselves, alone they only tell part of a complete game story.

So what we need is a mix of the XNA Platformer with the Game State Management recipes.

Aaron Stebner via his Link to samples that merge the XNA Game Studio 4.0 platformer starter kit with the game state management sample post has pointed us to just that.

Mach X Games - You’ve Got Your Gamestate Management Sample In My Platformer

"... I added a couple of versions to the merged Platformer/Gamestate Management sample that I did as a result of a question on the AppHub forums. Here are all the relevant links:

Bare bones merged version
+ lives
+ scrolling level
+ power-ups
+ moving tiles"

(Please click through to the post to get the downloads... I didn't want to leach all his traffic...)

So what's so the big deal about menus?

The issue is XNA development isn't your WinForm/WPF/SilverLight kind of development. In XNA you are responsible for drawing everything, in code. There's no GUI designer. There's no draggy and droppy. Code, code, code, everything is in code.

This means some things that are simple in a form based world become harder in a game loop world. Like option screens, etc.

Enough chatting, lets look at the some code. Here's a snap of what it takes to draw a a Level

Lets looks at the before and after, to see just how much we're getting. Here's the original Platformer

Note: If you download the Platformer code and you see this when running it;


Try changing the Game Profile property to "Reach" (via the Project Properties)


Here's a snap of the solution for the mega merged version ( Bare bones merged + lives + scrolling level + power-ups + moving tiles) which shows off the Main Menu, lives and side scrolling.



To give you a feel for the project, here's a snap of the Visual Studio Solution


So how's the Main Menu done?


It's the mixing in of the Game State Management that makes this fairly easy, much easier than you having to re-invent this wheel and code it all from scratch yourself.

Something I found pretty cool in the Platformer is how the Levels are mapped. Each level map is actually just a text file.

Here's the original first level;

And the new first level with side scrolling support;

Hopefully this has wet your appetite a little and give you something to play with this weekend... Smiley

The Discussion

  • User profile image

    "has wet your appetite" -> "whetted your appetite"
    'Whet' is an interesting word. :)

  • User profile image

    @Ricky: Thanks. Smiley

  • User profile image

    Shame of the spam. Anyway, great linking to content Greg! I have been working in XNA for a few months now and was looking for more concrete examples using the Game State Managment.

    Although I don't get the feeling this is really tight integration. Just bare-bones and then adding features to it. I would like to see a 'saving' option and how the settings set in the option screen could be used.

    How to communicate between the different screens should be added, altough this sample is very nice in it's simplicity.

    Also it doesn't use any GameComponent (except the screenmanager) and calls updates and draws manually. I'm wondering if the code could be simplified by maken use of Gamecomponents.

  • User profile image

    @CKurt: Yeah the spam hunt is "fun." I subscribe to all my posts comment feeds and try to kill the spam as I see it, but it's a pretty manual process...

    I'll keep an eye open for more Game State Management stuff and try to get it in if I find anything cool, provides more depth, etc.

    Thanks  Smiley 

  • User profile image

    Wow! Fast reply! Thx Duncan! You are a real asset to the Coding4Fun team!

  • User profile image
    Joe S

    im REALLY hoping for an answer here, im trying to get the merged version to work on the Xbox, i used the "Create copy for xbox 360" or w.e in the project and tried to deploy it, my xbox starts deploying, says complete and then resumes waiting for connection, any ideas? please help.

  • User profile image
    forex review

    This will be a terrific web page, might you be interested in doing an interview regarding just how you created it? If so e-mail me!

Add Your 2 Cents