Partilhar via


Walkthrough: create a simple Windows Store game with DirectX

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

In this set of tutorials, you learn how to create a basic Windows Store game with DirectX and C++. We cover all the major parts of a game, including the processes for loading assets such as arts and meshes, creating a main game loop, implementing a simple rendering pipeline, and adding sound and controls.

We show you the Windows Store game development techniques and considerations. We don't provide a complete end-to-end game. Rather, we focus on key Windows Store DirectX game development concepts, and calls out Windows Runtime specific considerations around those concepts. We walk through much of the code for the Windows Store Direct3D shooting game sample and look at the different components that make up the game.

Objective

  • To use the basic concepts and components of a Windows Store DirectX game, and to become more comfortable designing Windows Store games with DirectX.

What you need to know before starting

Before we get started with this tutorial, you need to be familiar with these subjects.

  • Microsoft C++ with Component Extensions (C++/CX). This is an update to Microsoft C++ that incorporates automatic reference counting, and is the language for developing a Windows Store games with DirectX 11.1 or later versions.
  • Basic linear algebra and Newtonian physics concepts.
  • Basic graphics programming terminology.
  • Basic Windows programming concepts.
  • Basic familiarity with the Direct2D and Direct3D 11 APIs.

The Windows Store Direct3D shooting game sample

You can download and browse the code for this tutorial here as a Microsoft Visual Studio 2013 project.

This sample implements a simple first-person shooting gallery, where the player fires balls at moving targets. Hitting each target awards a set number of points, and the player can progress through 6 levels of increasing challenge. At the end of the levels, the points are tallied, and the player is awarded a final score.

The sample demonstrates the game concepts:

  • Interoperation between DirectX 11.1 and the Windows Runtime
  • A first-person 3D perspective and camera
  • Stereoscopic 3D effects
  • Collision detection between objects in 3D
  • Handling player input for mouse, touch, and Xbox 360 controller controls
  • Audio mixing and playback
  • A basic game state machine

In this section

Topic Description

About the Windows Store game sample

Before you get started, be familiar with the game and the code discussed in these tutorials. While there's quite a bit of code, we won't discuss all of it, especially the code that's part of a Microsoft Visual Studio project template or common to other Direct3D samples. This topic helps you determine the difference between what's important when reviewing this code, and what's important when designing your own game.

Set up the game project

The first step in assembling your game is to set up a project in Visual Studio in such a way that you minimize the amount of code infrastructure work you need to do. You can save yourself a lot of time and hassle by using the right template and configuring the project specifically for game development. We step you through the setup and configuration of a simple game project.

Define the game's Windows Store app framework

The first part of coding a Windows Store game is building the framework that lets the game object interact with Windows. This includes Windows Runtime properties like suspend/resume event handling, window focus, and snapping, plus as the events, interactions and transitions for the user interface. We go over how the sample game is structured, and how it defines the high-level state machine for the player and system interaction.

Define the main game object

Now, we look at the details of the game sample's main object and how the rules it implements translate into interactions with the game world.

Assemble the rendering framework

Now, it's time to look at how the sample game uses that structure and state to display its graphics. Here we look at how to implement a rendering framework, starting from the initialization of the graphics device through the presentation of the graphics objects for display.

Add a user interface

You've seen how the sample game implements the main game object as well as the basic rendering framework. Now, let's look at how the sample game provides feedback about game state to the player. Here, you learn how you can add simple menu options and heads-up display components on top of the 3-D graphics pipeline output.

Add controls

Now, we take a look at how the game sample implements move-look controls in a 3-D game, and how to develop basic touch, mouse, and game controller controls.

Add sound

In this step, we examine how the shooting game sample creates an object for sound playback using the XAudio2 APIs.

Extend the game sample

Congratulations! At this point, you understand the key components of a basic Windows Store DirectX 3D game. You can set up the framework for a game, including the view provider and rendering pipeline, and implement a basic game loop. You also can create a basic user interface overlay, and incorporate sounds and controls. You're on your way to creating a game of your own, and here are some resources to further your knowledge of DirectX game development.

 

Downloading the full game sample

You can download the complete game sample in the MSDN Gallery.