Windows Phone 8 Game Development

By Marcin Jamro
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting Started

About this book

Currently almost everyone has a mobile phone that is used not only for calling, texting, and browsing the Internet, but also as an entertainment and social platform. Developers can create advanced 3D games with outstanding functionality that allow the player to enjoy the game directly on the mobile phone and cooperate with other players via the Internet!

Windows Phone 8 Game Development is a practical, hands-on guide that will show you how to create a 3D game for the Windows Phone 8 platform. From setting up the environment to publishing your game, you will first learn how to implement 3D and 2D graphics with Direct3D, XAML, C++, and C#. We will then look at the game logic, steering with sensors, detecting collisions, as well as using maps, geolocation, augmented reality, social networks, and web services to share data between players. Featuring many code examples, images, and diagrams you should find the content both engaging and easy to understand.

Publication date:
September 2013


Chapter 1. Getting Started

As mentioned in the preface, mobile phones are nowadays extremely popular, not only for communicating with people, but also to perform the role of powerful game environments with really outstanding functionalities. What is even more interesting is that you can create your own solutions for mobile devices that can be easily downloaded and used by people from various countries all over the world!

This is the first chapter of the book, which is prepared as a practical hands-on guide, presenting a step-by-step description on how to create a game for the Windows Phone 8 platform. However, it will not be just the simple game with a very limited functionality, because you will learn how to equip it with 2D and 3D graphics, audio and video support, maps, geolocation, augmented reality, speech recognition and synthesis, as well as integration with social networks, exchanging data via web services, and even more!

As you could see, there is a lot of content to get to know. However, at the beginning you should learn some basic information regarding the Windows Phone platform, and especially its newest version named Windows Phone 8, as well as the managed, native, and hybrid development approaches. Such subjects are presented in this chapter, together with an instruction on how to prepare the environment for developing the first game. Then, you will get to know the objective, rules, screens, and architecture of the game created as the example in the book.

Let's start the adventure with programming games for the Windows Phone 8 platform!


Windows Phone platform

The book is related to development of games for the Windows Phone. It is one of the existing mobile platforms, and is created by Microsoft. Its newest version (Windows Phone 8) was released in the last quarter of 2012. It works under the control of Windows Phone 8.0 OS that is different from Windows Phone 7.1 OS installed on Windows Phone 7.5 devices. However, on Windows Phone 8 devices you can also launch applications developed for the previous version of this operating system.

The Windows Phone platform introduces a new design of system and applications that is known as Modern UI. The main menu of the phone uses tiles (as in the following screenshot on the left) that perform the role of hyperlinks to various parts of the mobile environment, including applications and contacts. The user can easily select a set of operations that are frequently used and get access to them directly from the main menu. Tiles can present useful information, such as the number of incoming calls, unread text messages or e-mails. There are a few available sizes and types of tiles, thus you can adjust the main screen in a really comfortable way.

Since Windows Phone 7, the Marketplace (currently the Windows Phone Store) is chosen as a centralized place where users can browse, read details, and purchase or download applications. Therefore, the possibility of installing programs directly on the device, without a necessity of downloading them from the store, is restricted. Of course, developers can easily put their software directly on the developer unlocked devices to test it before publishing to the store.

The Windows Phone platform supports integration with many Internet sources, including social networks (such as Facebook and Windows Live), and e-mail accounts. These sources can be automatically updated, and data can be presented to the user in a comfortable way, for example, by informing about an incoming e-mail messages and using pictures from Facebook as images representing contacts in the phone.

The Windows Phone platform introduces some specific buttons, which make it possible to go back, show the main menu, and search data in various sources, including the Internet with the usage of Bing.

A design of the system can be adjusted by specifying the background type (dark or light), as well as an accent color that is visible in the main menu and application list. The newest Windows Phone version supports three screen resolutions—two in ratio 15:9 (480 x 800 and 768 x 1280 pixels) and one in 16:9 (720 x 1280 pixels).

As for the internal concepts, the Windows Phone 8 platform is similar to the Windows 8 operating system which is installed on desktops, notebooks, and tablets. One of the visible similarities is an existence of the Windows Phone Runtime that has many features common with its Windows 8 desktop version, named Windows Runtime. As mentioned at, the Windows Phone Runtime provides the infrastructure and many features dedicated to the phone, including APIs for sensors and location. The Windows Phone Runtime is accessible from any programming model used while developing applications for this platform.


Managed, native, and hybrid development

Windows Phone 8 introduces a lot of new features that are useful not only for users, but also for developers. The most important modification, from a perspective of this book, is related to types of projects that are supported. As of this version, you can create applications that use either the managed or the native code. Both approaches have some advantages and limitations, so it is important to understand the differences between them and choose suitable one depending on the project type and specificity.

Managed approach

Generally speaking, in the managed approach, an additional runtime environment has a significant role. The additional program is necessary, which compiles the code that is available as the intermediate code instead of the native one.

The managed approach has many advantages, including a possibility of running the prepared program on various target platforms that are equipped with a suitable runtime environment. Apart from that, solutions created in managed languages can use advanced security mechanisms and complex memory management systems, including a garbage collector, available out-of-box. What is more, using the managed approach may be really convenient for the developer and allow creating a project in an easier and faster way, for instance, while preparing a user interface or a library with business logic. Besides visible advantages, the managed programming has some limitations, which can be seen in performance-related problems and higher usage of resources, for example, while rendering complex 3D graphics or processing video clips.

In case of the Windows Phone 8 platform, the managed approach is supported by C# language together with XAML that are shortly presented in Appendix B, Languages and Technologies.

Native approach

The native approach differs significantly from the managed one. Generally, the native application does not require any dedicated runtime environment, because it is executed directly by the operating system. It can lead to better performance of the solution, because no operations related to execution of the intermediate code have to be performed.

However, the developer may be also responsible for preparing some basic security checks and memory management procedures. Therefore, the process of native development is more complex and can be more challenging to the programmer. With a proper creation, it can lead to elimination of some performance-related problems that can occur if the application is created with managed languages.

The native development can be especially useful for creating games that use complex 3D graphics and perform a lot of calculations related to movement of the player, image processing, and collision detection. These tasks often require high performance and sometimes it is not possible to be achieved with the usage of managed development and surrounding technologies.

In case of Windows Phone 8, the native approach is used in projects created in the C++ language with the usage of Direct3D technology. It is a really powerful scenario that allows the developer to use existing parts of code, which are prepared in C++, or even include additional middleware solutions, such as advanced systems for collision detection.

Hybrid approach

As you could see, both managed and native approaches have some advantages and disadvantages. For this reason, a very interesting way of application development combines these approaches. It allows the user to create various parts of the project in different techniques, using selected languages and technologies.

The division can be made according to the technology support for performing certain operations, or by performance requirements. As presented in the following figure, the managed approach can be chosen to create the user interface and prepare business logic in the form of a managed library. The native approach is useful in case of time-consuming data calculations, which require high performance. This kind of development is also chosen for processing graphics and videos in the most efficient way.

Using the hybrid approach, the application benefits from both types of development, and therefore can eliminate some problems, especially related to the performance, while still being convenient for the developer who needs to prepare the user interface or business logic in an easier and faster way.

The Windows Phone 8 platform supports the hybrid development by combining a part created in C++ and Direct3D with another one that is based on C# and XAML. Such an approach is really useful in case of games, and is described in this book.


First steps

The developers use various IDEs (Integrated Development Environments) for software creation, depending on programming languages, technologies, the number of people participating in the project, integration with source control management systems, and even continuous integration servers. Many different languages and technologies result in several IDEs being currently available for developers. Apart from IDEs, some additional tools (such as emulators, profilers, or configuration managers) are useful during development and can help to remove possible errors from the software.

Software Development Kit

For programming applications and games for the Windows Phone 8 platform, a specialized SDK (Software Development Kit) is available. It is called Windows Phone SDK 8.0 and contains several tools that form a complete environment for mobile development, including:

  • IDE—Microsoft Visual Studio Express 2012 for Windows Phone

  • Emulators for the Windows Phone 7 and 8 platforms

  • Many useful applications, for example, for registering the phone

  • SDKs for additional technologies

To install the SDK, you need to download the installer from the site To use the IDE, together with emulators, the PC has to run under the 64-bit Windows 8 operating system in Professional edition or greater, with the Hyper-V enabled. What is more, the processor has to support the hardware-assisted virtualization, the Second Level Address Translation (SLAT), and the hardware-based Data Execution Prevention (DEP). More details and additional requirements are presented at

Integrated Development Environment

Windows Phone 8 applications can be developed using various versions of Microsoft Visual Studio 2012 IDE, including:

  • Ultimate, Premium, and Professional—supporting a lot of features useful during creation of projects combining various technologies

  • Express versions—dedicated to a specific technology and containing a limited subset of features (in comparison with the versions mentioned earlier)

For creating the game described in this book, the Microsoft Visual Studio Express 2012 for Windows Phone is used. It is available for free, and often is sufficient for development of simple projects. After SDK installation, a shortcut to the IDE should be available in the Start menu.


If you already have another version of Microsoft Visual Studio 2012 (for example, the Ultimate one), you can also use it to create applications for Windows Phone 8. During installation of the Windows Phone SDK 8.0, some add-ons will be configured automatically.

The Microsoft Visual Studio Express 2012 for Windows Phone has to be registered online. A suitable website is opened after selecting the Register Product option from the Help menu. You need to log in to the Microsoft account and then fill an online form. Then, the product key is generated and shown on the website, as well as sent to the e-mail address. After pasting it to the window in the IDE, the software should be successfully registered and the message Product Key Applied should be displayed.

Developer account registration

An installation of the SDK is not sufficient for publishing created applications and games in the Windows Phone Store. For performing this operation, as well as for testing the software on a phone, the developer account is required. A process of its creation is quite simple and is described at the website

After the successful registration, you can log in to the Windows Phone Dev Center and display the Dashboard, where a lot of useful information is presented. It includes account data, information about registered phones, and some reports. In case of publishing paid applications, it is also important to complete the tax profile and provide other required information, according to messages available on the website with the account summary.

Phone registration

After the successful creation of the developer account, it is useful to register the mobile phone, which will be used later during development. This makes it possible to test the created application or game also on a real device, and is really important before publishing the project to the store.


For each developer account, three devices can be registered.

To register the Windows Phone 8 device, you should perform the following steps:

  1. Connect it to the computer via a USB cable and unlock the screen. Then, the phone should be automatically recognized by the operating system.

  2. Enable cellular data transmission or configure Wi-Fi connection on the phone.

  3. Run the Windows Phone Developer Registration tool (installed with the SDK) on the developer machine (for example, from the Start menu).

  4. Ensure that the tool presents a status Identified Windows Phone 8 device. Click on the Register button to unlock the phone.

  5. Click on the Register button, and type the credentials for the Microsoft account on the site that is opened in a new window.

After a few seconds, the status should be changed to Congratulations! You have successfully unlocked your Windows Phone. Now you can see information about the phone at Dashboard in the Windows Phone Dev Center. Apart from displaying data of registered phones, you can also remove some phones and check dates of their registrations.


Concept of the game

The book focuses mainly on practical aspects of game development, which are dedicated to the Windows Phone 8 platform. During the following chapters, a process of game creation is presented with the usage of many screenshots, listings of code, and detailed descriptions to make understanding of the content easier.

Currently, you have a configured development environment, consisting of the IDE and a set of emulators. You should also possess a developer account and a registered device. It means that everything required for beginning development is ready, and you can start creating the game! Its objective, screens, and architecture are described in this section.


The game is named Space Aim 3D and its main objective is to steer the space rocket to reach the target planet. The user needs to rotate the phone to indicate a direction of the rocket to avoid asteroids. The game presents 3D graphics and displays a world from a perspective of the rocket, as shown in the following screenshot (on the right). On reaching the planet, a level number is increased. While the rocket passes asteroids, the user gets points.

The game contains an unlimited number of levels, but with consecutive ones the difficulty increases, which is visible by an increased speed and a higher number of asteroids. The user has a limited number of rockets, but can get more by achieving a specified number of points. By default, after every 100,000 points, an additional rocket is obtained by the user. When the rocket crashes with an asteroid, the rocket is broken, and the user needs to use another one. The game ends when the player runs out of rockets.


The game uses a set of screens (also referred as pages) which can be opened only in a specific order. The screens are shown in the following figure as circles with names inside. They are connected through arrows presenting ways how the user can change the currently active screen. For instance, the player can navigate from the Menu screen to the Help one, and return in exactly the same way. The more complex example involves the Game page. In this case, the player can navigate from the Menu to Game, but returning is possible only through Pause or Result screens.

Pages are divided into the native and managed part. As presented in the previous figure, the Game, Pause, and Result screens are implemented using the native development approach. The rest of pages are included in the managed part of the project.

The main page is named Menu and is launched just after starting the application. From this screen, it is possible to run the game (after clicking on Play!), and navigate to Map, World, Ranks, Settings, Web, and Help pages, as shown in the following figure (on the left). The microphone icon will be used to start a process of navigating to another screen, based on the speech recognition result. A background of the page is prepared as an image representing space.

The Game page is shown while playing, and displays the game world from the perspective of the space rocket. The view includes asteroids and the target planet. By using 3D graphics, these objects are getting bigger while the rocket is coming closer. Some additional information (a number of the current level and remaining rockets, as well as a score) is displayed at the bottom, as presented in the preceding figure (on the right).

It is possible to pause the game while in play. In such a case, the additional screen (Pause) is displayed, as shown in the following figure (on the left). Then, the user can easily resume the game, restart it from the first level, as well as return to the main menu. As mentioned earlier, the game ends when the user runs out of rockets. In this case, a special screen, named Result, is presented. It contains information about the score and level, as well as buttons navigating to the main menu and restarting the game, as indicated in the following figure (on the right). What is more, the player can send the result, thus it can be taken into consideration while calculating the overall top scores.

Apart from the previously described screens, the application is equipped with a few other pages, including Map, which is presented in the following sketch (on the left). It shows the current location, as well as positions of other players in the vicinity using GPS data. The Map page also allows launching navigation to the last location of another player. GPS coordinates, together with player names, are processed by the dedicated web service located at an external server. By default, sending current location data is disabled, thus other players do not see your indicator on the map. However, when it is enabled, the current location of the player can be seen by anyone.

The World screen performs a similar role to the Map one. However, it presents data in the augmented reality, thus special indicators represent location of other players in the 3D world, as shown in the following figure (on the right). In the background, you can see the image from the camera. What is important, a size of indicator depends on a distance to the player, thus it is bigger while the player is closer. The World page supports launching navigation to another player, as well.

The Ranks screen is presented in the following figure (on the left) and shows the top scores from the game, divided into three categories:

  • Local - Only from the single device

  • Last 24h - Achieved by anyone, but with time limitation (24 hours)

  • Overall - Achieved by anyone, without time restrictions

Only the ten best results in each category are shown, with a player name and score. By default, all results are stored only locally. To send them to the global score, the player should click on the Send result button in the Result page.

The next screen, called Settings, makes it possible to adjust game preferences, divided into two groups, related to the user and to the game, as visible in the following figure (on the right). The first one allows you to specify the player name and open the website with the privacy policy.

The other is used to select a suitable music volume, enable or disable vibrations, as well as indicate whether sending the current GPS location is enabled.

The Web page supports operations regarding the social networks, as well as obtaining the last information from RSS feed, and opening the project website. On the left of the Web page, two groups are available (Facebook & Twitter and Rate), as presented in the following figure (on the left). The first one makes it possible to publish an update on the Facebook wall and tweet about the Space Aim 3D game. The other just allows the player to rate the game.

The last screen of the game (Help) is shown in the following figure (on the right), and contains some information about the game aim, steering, and contact details. They can be read by the user in case of any problem with the game or just after its installation. In the Contact group, the player can open the project website and its Facebook profile, as well as send an e-mail to the author.


The game requires sharing information between players, including their locations and results. For this reason, the architecture of the game cannot consist only of the game created for a mobile device.

In the proposed solution, a web service acts as a central point between the players. It is located on the external server and allows the clients (games on mobile phones) to send and receive data. To persist information, all required data are stored in a database, also located on the same server, as presented in the following diagram:

A connection with the web service is used in case of a few screens, including the Map one to send the current location and update data of players present in the vicinity.

It is worth mentioning that the mobile game can also communicate with external parts, related to Facebook and Twitter social networks. They are used to post a message on the Facebook wall, as well as to update a status at Twitter.

Programming languages and technologies

The book presents the hybrid development approach, thus you will use a few technologies to create an exemplary game. They are chosen based on the difficulty they introduce while building various parts of the project, such as a user interface or a web service. Languages and technologies can be divided into two groups, used for development of native and managed parts of the project, as shown in the following diagram:

The integrated development environment is a tool that is used for creation of all project parts. However, the game uses various languages and technologies, thus you will use two IDEs: Microsoft Visual Studio Express 2012 for Windows Phone (for creating the game) and Microsoft Visual Studio Express 2012 for Web (to prepare the web service).

The first group of languages and technologies is dedicated to the managed development. It contains C# language, .NET Framework, XAML, and WCF. The managed approach allows us to create the user interface and the business logic in an easy way. However, the most important part of the game uses the native development, together with C++ language, C++/CX (C++ Component Extensions), and Direct3D technology. Therefore, a particular part of the game can achieve better performance.

Short information about languages and technologies used for creation of the Space Aim 3D game is presented in Appendix B, Languages and Technologies.



The chapter is just an introduction to the process of developing the game for the Windows Phone 8 platform, which is a main subject for the whole book. With the still increasing possibilities of mobile devices, the developers can create outstanding projects that are sometimes even similar to their desktop or console versions! A lot of new technologies, 3D graphics, sensors, wireless communication, as well as huge computing power allow creating great projects that can be used by people all over the world! It can be even more interesting if you take a look at statistics presented in the preface. Without any doubts, the mobile gaming is important and you can also participate in it by creating your own solutions!

This chapter presented the Windows Phone 8 platform, including various development approaches: managed, native, and hybrid. A proper selection can make the development easier and eliminate some problems, for example, with performance. To present many interesting features, the hybrid approach is selected as the leading subject for the book.

You learned how to install the SDK with IDE, as well as create a developer account and register the phone. Thus, you should have a complete environment that allows to start developing the first game. Its concept, objective, screens, and architecture were described in this chapter, as well.

Currently, you know what the aim for the whole book is, so let's proceed to the next chapter, set up a new project, and learn how to create the first screen for the game!

About the Author

  • Marcin Jamro

    Marcin Jamro, PhD, is an entrepreneur and researcher, as well as a developer and architect of various kinds of applications. He is the President of the Board at TITUTO Sp. z o.o. [Ltd.] in Rzeszów, Poland.

    Marcin is interested in many aspects of computer science, including software engineering and project management. He is an author of two other books, namely Windows Phone 8 Game Development (2013) and Windows Application Development Cookbook (2017), both by Packt Publishing.

    Marcin has published several papers, participated in many conferences, organized a few of them, and participated in two internships at Microsoft in Redmond, USA. He has the MCP, MCTS, and MCPD certificates.

    Browse publications by this author