Chapter 7. 2D User Interface in 3D Game

In the previous chapter, you improved the first prototype of the game by adding support for sensors. Currently, it is possible to steer the rocket by moving the phone, and increase or decrease its speed. What is more, the game supports multiple levels and counting score, while the rocket is flying and when it reaches the target planet.

In this chapter, you will learn how to use 2D graphics with DirectXTK library to create the rocket display, countdown at the beginning of each level, and the menu displayed when the game is paused or finished. At the end of the chapter, you will have the playable version of Space Aim 3D without additional features but allowing the player to steer the rocket, reach planets, and see results. The user will also be able to pause the game, restart it, and return to the Menu screen.

DirectX Tool Kit

For developing parts of the game with 2D graphics, you can use an additional library called DirectXTK (DirectX Tool Kit). According to information available at the project website (http://directxtk.codeplex.com), it is:

a collection of helper classes for writing Direct3D 11 code in C++.

Among supported platforms, Windows Phone 8 is also available. Therefore, you can benefit from its various features, including 2D sprites and text rendering. Of course, the library contains a lot of interesting functionalities, however, only some of them will be used in your game.

To use classes available in DirectXTK, you need to add this project into your solution. A step-by-step description of this process is presented in this section. Useful information can be also found at http://directxtk.codeplex.com/wikipage?title=DirectXTK.

At the beginning, download the DirectXTK.zip file from its website and extract the archive. Then, add the DirectXTK_WindowsPhone8 project into the SpaceAim3D solution. To do this, choose the Add and Existing Project options from the context menu of the solution (not projects), and choose the DirectXTK_WindowsPhone8.vcxproj file. Just after adding the project, it should be visible in the Solution Explorer window.

The next step consists of adding a reference to the DirectXTK_WindowsPhone8 project in the SpaceAim3DComp project, because you will use the DirectXTK library in the native part of your game. To do this, you should select the References option from the context menu of the SpaceAim3DComp project. In the new window (named SpaceAim3DComp Property Pages), click on the Add New Reference button, select a proper project (from the Solution group), and click on OK. Then, set a value for the Reference Assembly Output property (on the right, inside the Build Properties group) to False. At the end, click on OK.

Next, select the Properties option from the context menu of the SpaceAim3DComp project. It opens a new window, the same as used previously to add a reference. This time you should change the Configuration option (at the top) to All Configurations, and Platform to All Platforms. The main action that should be currently performed in this window is setting a suitable include directory that contains files of DirectXTK. You can achieve this by selecting the C/C++ node (from the tree on the left), choosing the Additional Include Directories property, and clicking on the Edit option, as presented in the following screenshot:

DirectX Tool Kit

In the newly opened window (Additional Include Directories, as shown in the following screenshot), click on the icon for new line, and then on a button with dots. It allows you to select a location of the Inc directory in the DirectXTK project. At the end, click on the OK button. Now you can also close the SpaceAim3DComp Property Pages window, by clicking on OK.

DirectX Tool Kit

You have already configured the DirectXTK library. Now you can rebuild the whole solution, by choosing the Build and Rebuild Solution options from the menu. This process can take a bit more time than before, because an additional project also needs to be built. However, at the end, you should see an information that all three projects have been rebuilt successfully.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.66.128