A menu for an(y) XNA game

So, my current project is to make a game, as you might have guessed. Ideally I want it to be so darn good I can sell it through some distribution service for a very reasonable price.

My first sub project (I’m easily bugged by not having certain ‘features’ of programs during development) was to build a menu that extended GameComponent, and was a pluggable, easy to implement menu. It has no flashy features (currently) and is not quite ready to release (it’s clean running, but I want to make the code a bit more flexible for possible future features). When it’s ready I’ll make it available on bomadeno.com

Using only a few lines of code, the menu looks like this:transparentsilvermenu

And by picking that irresistible button…

transparentbunnymenuA semi transparent bunny fill the image. Obviously (or not?) a bunny would not be the image of choice in a real game, but it allow you a few important choices:

  • The menu background is an image showing some beautiful prerend of a scene in your game
  • The menu is a transparent grey, using the real game (paused, potentially) in the background as an image
  • A plain colour
  • A slightly transparent image of something (maybe stars, clouds?) over the background. Although I haven’t tested it, pngs with transparency data should work too.

In case you’re wondering, the blue tint in these images is the ‘game’ showing through – a default otherwise unedited XNA project.

The features, then:

Choice of menu title position and menu items position (auto aligning to look best). Choices are top and bottom lefts and rights, and centred. Menu items can be automatically stacked under the menu title.

Menu item active and inactive colours can be set (the title is inactive colour, but I’m planning to make that so you can set it differently)

Menu items are added in the form of text-delegate pairs – so you have complete control over what they do. The menu listens for Escape key presses, and can hide and show itself. When hidden by escape it calls a user set ‘pause’ and ‘resume’ delegate to give you control over your game when the menu shows itself. You don’t actually have to set these… the menu will then just show and hide itself.

All in all, to get a menu with 2 options (resume/quit, maybe?), you need only 6 lines of code, and a simple but functional menu will work alongside your existing game. (not counting the methods that respond to resume/exit – I’m assuming you already have them. It makes the required lines of code look better! If you must be picky, the methods take another 6-7 lines depending on what you put in them)

Next time – I’ll either have added some game to the menu (woo), flashed up the menu some, or quite possibly done something totally different… You will have to wait and see!

Advertisements

3 thoughts on “A menu for an(y) XNA game”

  1. You say we “will have to wait and see” like we’re holding our breaths to hear more about your exciting codes and algorithms… Geek 8D~


    On a different note :D… BUNNY!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s