Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building your First Mobile Game using XNA 4.0

You're reading from   Building your First Mobile Game using XNA 4.0 A fast-paced, hands-on guide to building a 3D game for the Windows Phone 7 platform using XNA 4.0

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849687744
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Thomas Goussaert Thomas Goussaert
Author Profile Icon Thomas Goussaert
Thomas Goussaert
Brecht Kets Brecht Kets
Author Profile Icon Brecht Kets
Brecht Kets
Arrow right icon
View More author details
Toc

Menu scene


We will start this demo from a fresh project that you can find in the StartFiles folder. This project already contains all the assets and a basic folder setup that will help us organize our game files.

We will create a simple menu with two buttons, one to start the game and another one to exit the game. Let's start by creating a new class called MenuScene that inherits from GameScene.

public class MenuScene :GameScene

Fields

Our class will have four fields: a background, two buttons, and a SoundEffect class.

private GameSprite _background;
private GameButton _startButton;
private GameButton _exitButton;
private Song _backgroundMusic;

Constructor

The constructor remains empty but we need to pass the name of this scene to the base class.

public MenuScene():base("Menu"){}

Initialize

In this method, we will initialize the background and the buttons. The PivotPoint property of the buttons is set at the top-middle; this will make it easy to position them on the middle of the screen. We also add...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image