使用 DirectX 建立簡單的通用 Windows 平台 (UWP) 遊戲Create a simple Universal Windows Platform (UWP) game with DirectX

在這組教學課程中,您將瞭解如何使用 DirectX 和 c + +/WinRT 來建立基本通用 WINDOWS 平臺 (UWP) 名為 Simple3DGameDX的範例遊戲。In this set of tutorials, you'll learn how to use DirectX and C++/WinRT to create the basic Universal Windows Platform (UWP) sample game named Simple3DGameDX. 遊戲會在簡單的第一個第一員的第一次製作資源庫中進行。The gameplay takes place in a simple first-person 3D shooting gallery.

注意

您可以從這裡下載 Simple3DGameDX 範例遊戲本身的連結是 Direct3D 範例遊戲The link from which you can download the Simple3DGameDX sample game itself is Direct3D sample game. C + +/WinRT 來源程式碼位於名為的資料夾中 cppwinrtThe C++/WinRT source code is in the folder named cppwinrt. 如需其他 UWP 範例應用程式的詳細資訊,請參閱 取得 uwp 應用程式範例For info about other UWP sample apps, see Get UWP app samples.

這些教學課程涵蓋遊戲的所有主要部分,包括載入像是藝術和網格等資產的程式、建立主要遊戲迴圈、實行簡單的轉譯管線,以及新增音效和控制項。These tutorials cover all of 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.

您也會看到 UWP 遊戲開發技巧和考慮。You'll also see UWP game development techniques and considerations. 我們將著重于重要的 UWP DirectX 遊戲開發概念,並針對這些概念呼叫 Windows 執行時間專屬的考慮。We'll focus on key UWP DirectX game development concepts, and call out Windows-Runtime-specific considerations around those concepts.

目標Objective

瞭解 UWP DirectX 遊戲的基本概念和元件,並更熟悉使用 DirectX 設計 UWP 遊戲。To learn about the basic concepts and components of a UWP DirectX game, and to become more comfortable designing UWP games with DirectX.

您必須知道的事項What you need to know

在本教學課程中,您必須熟悉這些主題。For this tutorial, you need to be familiar with these subjects.

  • C + +/WinRTC++/WinRT. C + +/WinRT 是標準的現代 c + + 17 語言投射,適用于 Windows 執行階段 (WinRT) Api,實作為以標頭檔案為基礎的程式庫,並設計為提供您最先進的 Windows Api 存取權。C++/WinRT is a standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide you with first-class access to the modern Windows APIs.
  • 基本線性代數和牛頓物理概念。Basic linear algebra and Newtonian physics concepts.
  • 基本圖形程式設計詞彙。Basic graphics programming terminology.
  • 基本 Windows 程式設計概念。Basic Windows programming concepts.
  • 必須對 Direct2DDirect3D 11 API 有基本的認識。Basic familiarity with the Direct2D and Direct3D 11 APIs.

Simple3DGameDX範例遊戲會實行簡單的第一個第一次的3d 拍攝資源庫,讓播放者在移動目標上引發球。The Simple3DGameDX sample game implements a simple first-person 3D shooting gallery, where the player fires balls at moving targets. 擊中每個目標就會得到特定的分數,而且玩家可以晉級 6 個關卡,逐漸增加挑戰難度。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 these game concepts.

  • DirectX 11.1 與 Windows 執行階段的交互操作Interoperation between DirectX 11.1 and the Windows Runtime
  • 第一人稱 3D 遠近景深和相機A first-person 3D perspective and camera
  • 3D 立體視覺效果Stereoscopic 3D effects
  • 衝突-3D 中的物件之間的偵測Collision-detection between objects in 3D
  • 處理滑鼠、觸控以及 Xbox 控制器控制項的使用者輸入Handling player input for mouse, touch, and Xbox controller controls
  • 音訊混合和播放Audio mixing and playback
  • 基本遊戲狀態-電腦A basic game state-machine

作用中的遊戲範例

主題Topic 說明Description
設定遊戲專案Set up the game project 開發遊戲的第一個步驟是在 Microsoft Visual Studio 中設定專案。The first step in developing your game is to set up a project in Microsoft Visual Studio. 當您設定專門用於遊戲開發的專案之後,您稍後可以將其重新使用為一種範本。After you've configured a project specifically for game development, you could later re-use it as a kind of template.
定義遊戲的 UWP 應用程式架構Define the game's UWP app framework 編寫通用 Windows 平臺 (UWP) 遊戲的第一步,是建立可讓應用程式物件與 Windows 互動的架構。The first step in coding a Universal Windows Platform (UWP) game is building the framework that lets the app object interact with Windows.
管理遊戲流程Game flow management 定義高階狀態電腦,讓玩家與系統互動。Define the high-level state machine to enable player and system interaction. 了解 UI 如何與整體遊戲的狀態電腦互動,以及如何建立 UWP 遊戲事件處理常式。Learn how UI interacts with the overall game's state machine and how to create event handlers for UWP games.
定義主要遊戲物件Define the main game object 現在,我們來看看範例遊戲的主要物件的詳細資料,以及它所實行的規則如何轉譯成與遊戲世界的互動。Now, we look at the details of the sample game's main object and how the rules it implements translate into interactions with the game world.
轉譯架構 I:轉譯簡介Rendering framework I: Intro to rendering 瞭解如何開發呈現管線來顯示圖形。Learn how to develop the rendering pipeline to display graphics. 轉譯簡介。Intro to rendering.
轉譯架構 II:遊戲轉譯Rendering framework II: Game rendering 了解如何組合轉譯管線來顯示圖形。Learn how to assemble the rendering pipeline to display graphics. 遊戲轉譯、設定及準備資料。Game rendering, set up and prepare data.
新增使用者介面Add a user interface 瞭解如何將2D 使用者介面重迭新增至 DirectX UWP 遊戲。Learn how to add a 2D user interface overlay to a DirectX UWP game.
新增控制項Add controls 現在,我們來看看範例遊戲如何在3-d 遊戲中實行移動外觀控制項,以及如何開發基本的觸控、滑鼠和遊戲控制器控制項。Now, we take a look at how the sample game implements move-look controls in a 3-D game, and how to develop basic touch, mouse, and game controller controls.
加入聲音Add sound 使用 XAudio2 Api 開發簡單的音效引擎來播放遊戲音樂和音效效果。Develop a simple sound engine using XAudio2 APIs to playback game music and sound effects.
延伸遊戲範例Extend the sample game 了解如何實作 UWP DirectX 遊戲的 XAML 重疊。Learn how to implement a XAML overlay for a UWP DirectX game.