What Button was that

A reusable sample to help define controller schemes for your games

What Button was that?

Defining your games controls has never been easier

CropperCapture[27] When you develop your game, you're going to need a screen to explain to the player what button does what. You can create this in your favorite art program...or you could get all programmy on this job and make a dynamic screen to define your button actions.

I may have done the latter.

I created this "How to Play" screen so that you can quickly and easily define what buttons do things in your game and display that visually to the player with no need of creating new images for each new game you make. Using this object is extremely simple (probably some room for some enhancements too, but I'll leave that up to you). The controller images used in this sample were provide by Microsoft and can be obtained from the Creator's site here.

Also, before you get going, you should think about what controller buttons you're planning on using and what you're planning on having them do. Then take a trip over to MVP Jon Wattes's site to read up on the expected button actions and try to make sure your games controls are staying consistent with what players expect.

First, we start out by declaring our new "How to Play" object in our game class.

        HowToPlay mHowToPlay;

Next, we initialize our object in the LoadContent method of our game class. Definiting a Viewport and passing in the ContentManager object so that images and fonts can be loaded in the HowToPlay class.

            Viewport aViewport = new Viewport();
            aViewport.X = 0;
            aViewport.Y = 0;
            aViewport.Width = 1280;
            aViewport.Height = 720;
            mHowToPlay = new HowToPlay(Content, aViewport, this.graphics.GraphicsDevice);


Then, we define the controls for our game. This is done simply by setting the appropriate text object for our HowToPlay object. You can see how this is done in the code below.

            mHowToPlay.LeftTriggerText = "Rotate Left";
            mHowToPlay.RightTriggerText = "Rotate Right";
            mHowToPlay.DPadText = "Move";
            mHowToPlay.LeftThumbStickText = "Move";
            mHowToPlay.BackButtonText = "Exit";
            mHowToPlay.StartButtonText = "Pause Game";
            mHowToPlay.AButtonText = "Fire/Select";
            mHowToPlay.BButtonText = "Timewarp/Cancel";


Now we just need to draw our "HowToPlay" object.



And that's it. With just that simple small amount of code, we've got a lovely little control screen like this. If you don't define any text for the Right Trigger, Left Trigger, Right Shoulder and Left Shoulder then the top controller view won't be shown and the front control view will be centered on the screen appropriately.


With XBLCG, you should be striving to add as much polish and professionalism to your title as you possibly can. Hopefully this little sample can help you achieve that even easier. Enjoy it, enhance it and let me know what you think!

Technorati Tags: