定義主要遊戲物件Define the main game object

注意

本主題是使用 DirectX 教學課程系列 建立簡單通用 Windows 平臺 (UWP) 遊戲 的一部分。This topic is part of the Create a simple Universal Windows Platform (UWP) game with DirectX tutorial series. 該連結的主題會設定數列的內容。The topic at that link sets the context for the series.

一旦您配置了範例遊戲的基本架構,並且實行了可處理高階使用者和系統行為的狀態機器,您將會想要檢查將範例遊戲轉換成遊戲的規則和機制。Once you've laid out the basic framework of the sample game, and implemented a state machine that handles the high-level user and system behaviors, you'll want to examine the rules and mechanics that turn the sample game into a game. 讓我們看看範例遊戲主要物件的詳細資料,以及如何將遊戲規則轉譯成與遊戲世界的互動。Let's look at the details of the sample game's main object, and how to translate game rules into interactions with the game world.

目標Objectives

  • 瞭解如何套用基本的開發技術,以實行適用于 UWP DirectX 遊戲的遊戲規則和機制。Learn how to apply basic development techniques to implement game rules and mechanics for a UWP DirectX game.

主要遊戲物件Main game object

Simple3DGameDX 範例遊戲中, Simple3DGame 是主要的遊戲物件類別。In the Simple3DGameDX sample game, Simple3DGame is the main game object class. Simple3DGame的實例會透過應用程式:: Load方法間接建立。An instance of Simple3DGame is constructed, indirectly, via the App::Load method.

以下是 Simple3DGame 類別的一些功能。Here are some of the features of the Simple3DGame class.

  • 包含遊戲邏輯的執行。Contains implementation of the gameplay logic.
  • 包含傳達這些詳細資料的方法。Contains methods that communicate these details.
    • 將遊戲狀態變更為應用程式架構中定義的狀態機器。Changes in the game state to the state machine defined in the app framework.
    • 從應用程式到遊戲物件本身的遊戲狀態變更。Changes in the game state from the app to the game object itself.
    • 更新遊戲 UI 的詳細資料 (重迭和列印頭顯示) 、動畫和物理) (。Details for updating the game's UI (overlay and heads-up display), animations, and physics (the dynamics).

    注意

    圖形的更新是由 GameRenderer 類別所處理,該類別包含取得和使用遊戲所使用之圖形裝置資源的方法。Updating of graphics is handled by the GameRenderer class, which contains methods to obtain and use graphics device resources used by the game. 如需詳細資訊,請參閱轉譯 架構 I:轉譯簡介For more info, see Rendering framework I: Intro to rendering.

  • 可作為定義遊戲會話、層級或存留期之資料的容器,取決於您在高階定義遊戲的方式。Serves as a container for the data that defines a game session, level, or lifetime, depending on how you define your game at a high level. 在此情況下,遊戲狀態資料適用于遊戲的存留期,並且會在使用者啟動遊戲時初始化一次。In this case, the game state data is for the lifetime of the game, and is initialized one time when a user launches the game.

若要查看這個類別所定義的方法和資料,請參閱下面 的 Simple3DGame 類別To view the methods and data defined by this class, see The Simple3DGame class below.

初始化和啟動遊戲Initialize and start the game

當玩家啟動遊戲時,遊戲物件必須初始化它的狀態,建立和新增重疊,設定追蹤玩家表現的變數,以及具現化用來建立關卡的物件。When a player starts the game, the game object must initialize its state, create and add the overlay, set the variables that track the player's performance, and instantiate the objects that it will use to build the levels. 在此範例中,這是在應用程式:: Load中建立GameMain實例時完成的。In this sample, this is done when the GameMain instance is created in App::Load.

Simple3DGame類型的遊戲物件是在GameMain:: GameMain函式中建立的。The game object, of type Simple3DGame, is created in the GameMain::GameMain constructor. 然後,它會使用 Simple3DGame:: Initialize 方法,在 GameMain:: ConstructInBackground 引發和遺忘協同程式(從 GameMain:: GameMain呼叫)進行初始化。It's then initialized using the Simple3DGame::Initialize method during the GameMain::ConstructInBackground fire-and-forget coroutine, which is called from GameMain::GameMain.

Simple3DGame:: Initialize 方法The Simple3DGame::Initialize method

範例遊戲會在遊戲物件中設定這些元件。The sample game sets up these components in the game object.

  • 已建立新的視訊播放物件。A new audio playback object is created.
  • 已建立遊戲的圖形基本型別陣列,包括關卡基本型別、彈藥及障礙物陣列。Arrays for the game's graphic primitives are created, including arrays for the level primitives, ammo, and obstacles.
  • 已建立儲存遊戲狀態資料的位置 (名為 Game),並放在 ApplicationData::Current 指定的應用程式資料設定儲存位置。A location for saving game state data is created, named Game, and placed in the app data settings storage location specified by ApplicationData::Current.
  • 已建立遊戲計時器與初始的遊戲內重疊點陣圖。A game timer and the initial in-game overlay bitmap are created.
  • 已使用一組特定的檢視與投射參數建立新的相機。A new camera is created with a specific set of view and projection parameters.
  • 輸入裝置 (控制器) 設定為與相機相同的起始傾斜度與偏航角,因此玩家在起始控制位置與相機位置之間是 1 對 1 的對應。The input device (the controller) is set to the same starting pitch and yaw as the camera, so the player has a 1-to-1 correspondence between the starting control position and the camera position.
  • 已建立玩家物件並設定為使用中。The player object is created and set to active. 我們會使用球體物件來偵測玩家與牆和障礙物的距離,並讓相機進入可能會中斷深度的位置。We use a sphere object to detect the player's proximity to walls and obstacles and to keep the camera from getting placed in a position that might break immersion.
  • 已建立遊戲世界基本型別。The game world primitive is created.
  • 已建立圓柱形障礙物。The cylinder obstacles are created.
  • 已建立目標 (Face 物件) 並設置編號。The targets (Face objects) are created and numbered.
  • 已建立子彈。The ammo spheres are created.
  • 已建立關卡。The levels are created.
  • 已載入高分記錄。The high score is loaded.
  • 已載入所有先前儲存的遊戲狀態。Any prior saved game state is loaded.

遊戲現在具有 — 世界、玩家、障礙、目標和 ammo 球體的所有重要元件的實例。The game now has instances of all the key components—the world, the player, the obstacles, the targets, and the ammo spheres. 它也擁有關卡的執行個體,代表上述所有元件的設定,以及它們在每個特定關卡的行為。It also has instances of the levels, which represent configurations of all of the above components and their behaviors for each specific level. 現在讓我們看看遊戲如何建立這些層級。Now let's see how the game builds the levels.

組建和載入遊戲等級Build and load game levels

Level[N].h/.cpp 範例方案的 GameLevels 資料夾中找到的檔案中,會進行層級結構的大部分繁重工作。Most of the heavy lifting for the level construction is done in the Level[N].h/.cpp files found in the GameLevels folder of the sample solution. 因為它著重于非常特定的執行,所以我們不會在此討論。Because it focuses on a very specific implementation, we won't be covering them here. 重要的是,每個層級的程式碼都是以不同的 層級 [N] 物件來執行。The important thing is that the code for each level is run as a separate Level[N] object. 如果您想要擴充遊戲,您可以建立一個 層級 [N] 物件,該物件會接受指派的數位作為參數,並隨機放置障礙物和目標。If you'd like to extend the game, you can create a Level[N] object that takes an assigned number as a parameter and randomly places the obstacles and targets. 或者,您可以讓它從資源檔(甚至是網際網路)載入層級的設定資料。Or, you can have it load level configuration data from a resource file, or even the internet.

定義遊戲Define the gameplay

到目前為止,我們已經擁有開發遊戲所需的所有元件。At this point, we have all the components we need to develop the game. 層級已在原始物件的記憶體中建立,並已準備好讓玩家開始與互動。The levels have been constructed in memory from the primitives, and are ready for the player to start interacting with.

最佳的遊戲會立即對玩家輸入做出反應,並提供立即的意見反應。The best games react instantly to player input, and provide immediate feedback. 這種情況適用于任何類型的遊戲,從 twitch 行動、即時的玩射擊到審慎、輪流的策略遊戲。This is true for any type of a game, from twitch-action, real-time first-person shooters to thoughtful, turn-based strategy games.

Simple3DGame:: RunGame 方法The Simple3DGame::RunGame method

當遊戲等級正在進行時,遊戲會處於「 動態 」狀態。While a game level is in progress, the game is in the Dynamics state.

GameMain:: Update 是在每個畫面格更新應用程式狀態一次的主要更新迴圈,如下所示。GameMain::Update is the main update loop that updates the application state once per frame, as shown below. Update 迴圈會呼叫 Simple3DGame:: RunGame 方法,以在遊戲處於「 動態 」狀態時處理工作。The update loop calls the Simple3DGame::RunGame method to handle the work if the game is in the Dynamics state.

// Updates the application state once per frame.
void GameMain::Update()
{
    // The controller object has its own update loop.
    m_controller->Update();

    switch (m_updateState)
    {
    ...
    case UpdateEngineState::Dynamics:
        if (m_controller->IsPauseRequested())
        {
            ...
        }
        else
        {
            // When the player is playing, work is done by Simple3DGame::RunGame.
            GameState runState = m_game->RunGame();
            switch (runState)
            {
                ...

Simple3DGame:: RunGame 會處理一組資料,以定義遊戲迴圈目前反復專案的目前狀態。Simple3DGame::RunGame handles the set of data that defines the current state of the game play for the current iteration of the game loop.

以下是 Simple3DGame:: RunGame中的遊戲流程邏輯。Here's the game flow logic in Simple3DGame::RunGame.

  • 方法會更新計時器,以在完成層級之前將計數減少,並測試以查看層級的時間是否已過期。The method updates the timer that counts down the seconds until the level is completed, and tests to see whether the level's time has expired. 當時間結束時,這是遊戲的其中一項規則 — ,如果並非所有目標都已在使用中,則會進行遊戲。This is one of the rules of the game—when time runs out, if not all the targets have been shot, then it's game over.
  • 如果時間已用盡,則方法會設定 TimeExpired 遊戲狀態,並回到先前程式碼中的 Update 方法。If time has run out, then the method sets the TimeExpired game state, and returns to the Update method in the previous code.
  • 如果保留時間,則會輪詢移動外觀控制器以取得相機位置的更新;具體而言,就是從相機平面投射的觀點, (播放程式) 的角度,以及從上一次輪詢控制器以來移動角度的距離。If time remains, then the move-look controller is polled for an update to the camera position; specifically, an update to the angle of the view normal projecting from the camera plane (where the player is looking), and the distance that angle has moved since the controller was polled last.
  • 相機會依據移動視角控制器中的新資料進行更新。The camera is updated based on the new data from the move-look controller.
  • 更新動態,或是遊戲世界中與玩家控制無關的動畫及物件行為。The dynamics, or the animations and behaviors of objects in the game world independent of player control, are updated. 在這個範例遊戲中,會呼叫 Simple3DGame:: UpdateDynamics 方法,以更新已引發之 ammo 球體的動作、要件障礙的動畫以及目標的移動。In this sample game, the Simple3DGame::UpdateDynamics method is called to update the motion of the ammo spheres that have been fired, the animation of the pillar obstacles and the movement of the targets. 如需詳細資訊,請參閱 更新遊戲世界For more information, see Update the game world.
  • 方法會檢查是否符合層級的成功完成準則。The method checks to see whether the criteria for the successful completion of a level have been met. 如果是,它會完成層級的分數,並檢查這是否為最後一層 (6) 。If so, it finalizes the score for the level, and checks to see whether this is the last level (of 6). 如果是最後一個層級,則此方法會傳回 GameState:: GameComplete 遊戲狀態;否則,它會傳回 GameState:: LevelComplete 遊戲狀態。If it's the last level, then the method returns the GameState::GameComplete game state; otherwise, it returns the GameState::LevelComplete game state.
  • 如果層級未完成,則方法會將遊戲狀態設為 GameState:: Active,然後傳回。If the level isn't complete, then the method sets the game state to GameState::Active, and returns.

更新遊戲世界Update the game world

在此範例中,當遊戲執行時,會從Simple3DGame:: RunGame方法呼叫Simple3DGame:: UpdateDynamics方法 (從GameMain:: Update) 呼叫該方法,以更新在遊戲場景中轉譯的物件。In this sample, when the game is running, the Simple3DGame::UpdateDynamics method is called from the Simple3DGame::RunGame method (which is called from GameMain::Update) to update objects that are rendered in a game scene.

迴圈(例如 UpdateDynamics )會呼叫任何方法,這些方法是用來設定運動中的遊戲世界(與玩家輸入無關),以建立沉浸式遊戲體驗,並讓層級保持運作。A loop such as UpdateDynamics calls any methods that are used to set the game world in motion, independent of the player input, to create an immersive game experience and make the level come alive. 這包括需要轉譯的圖形,以及執行的動畫迴圈,即使沒有播放程式輸入,也能帶出動態世界。This includes graphics that needs to be rendered, and running animation loops to bring about a dynamic world even when there's no player input. 在您的遊戲中,這可能包括 swaying 的樹狀結構、沿著支援腳步線的波浪 cresting、機械吸煙,以及外部程式碼延展和四處移動。In your game, that could include trees swaying in the wind, waves cresting along shore lines, machinery smoking, and alien monsters stretching and moving around. 它也包含物件之間的互動,像是玩家環境和世界之間的碰撞,或子彈與障礙物和目標之間的撞擊。It also encompasses the interaction between objects, including collisions between the player sphere and the world, or between the ammo and the obstacles and targets.

除非遊戲特別暫停,否則遊戲迴圈應該繼續更新遊戲世界;這是以遊戲邏輯、實體演算法,還是單純的隨機方式來決定。Except when the game is specifically paused, the game loop should continue updating the game world; whether that's based on game logic, physical algorithms, or whether it's just plain random.

在範例遊戲中,此原則稱為 dynamics,它包含要件障礙的上升和下降,以及 ammo 球體的移動和實體行為(當它們被引發且在移動時)。In the sample game, this principle is called dynamics, and it encompasses the rise and fall of the pillar obstacles, and the motion and physical behaviors of the ammo spheres as they are fired and in motion.

Simple3DGame:: UpdateDynamics 方法The Simple3DGame::UpdateDynamics method

這個方法會處理這四組計算。This method deals with these four sets of computations.

  • 發射的子彈在世界的位置。The positions of the fired ammo spheres in the world.
  • 柱型障礙物的動畫。The animation of the pillar obstacles.
  • 玩家與世界界限的交集。The intersection of the player and the world boundaries.
  • 子彈與障礙物、目標、其他子彈和世界的碰撞。The collisions of the ammo spheres with the obstacles, the targets, other ammo spheres, and the world.

障礙的動畫會在 動畫 .h 的程式碼檔中定義的迴圈中進行。The animation of the obstacles takes place in a loop defined in the Animate.h/.cpp source code files. Ammo 和任何衝突的行為是由程式碼中提供的簡化物理演算法所定義,並由遊戲世界的一組全域常數(包括引力和材質屬性)進行參數化。The behavior of the ammo and any collisions are defined by simplified physics algorithms, supplied in the code and parameterized by a set of global constants for the game world, including gravity and material properties. 這些全都是在遊戲世界座標空間中計算的。This is all computed in the game world coordinate space.

檢查流程Review the flow

既然我們已更新場景中的所有物件,並計算出任何衝突,就需要使用此資訊來繪製對應的視覺效果變更。Now that we've updated all of the objects in the scene, and calculated any collisions, we need to use this info to draw the corresponding visual changes.

GameMain:: Update 完成遊戲迴圈的目前反復專案之後,此範例會立即呼叫 GameRenderer:: Render 來取得更新的物件資料,並產生新的場景來呈現給播放程式,如下所示。After GameMain::Update has completed the current iteration of the game loop, the sample immediately calls GameRenderer::Render to take the updated object data and generate a new scene to present to the player, as shown below.

void GameMain::Run()
{
    while (!m_windowClosed)
    {
        if (m_visible)
        {
            switch (m_updateState)
            {
            case UpdateEngineState::Deactivated:
            case UpdateEngineState::TooSmall:
                ...
                // Otherwise, fall through and do normal processing to perform rendering.
            default:
                CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(
                    CoreProcessEventsOption::ProcessAllIfPresent);
                // GameMain::Update calls Simple3DGame::RunGame. If game is in Dynamics
                // state, uses Simple3DGame::UpdateDynamics to update game world.
                Update();
                // Render is called immediately after the Update loop.
                m_renderer->Render();
                m_deviceResources->Present();
                m_renderNeeded = false;
            }
        }
        else
        {
            CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(
                CoreProcessEventsOption::ProcessOneAndAllPending);
        }
    }
    m_game->OnSuspending();  // Exiting due to window close, so save state.
}

呈現遊戲世界的圖形Render the game world's graphics

我們建議遊戲中的圖形經常更新,在理想的情況下,通常會與主要遊戲迴圈逐一查看的方式完全相同。We recommend that the graphics in a game update often, ideally exactly as often as the main game loop iterates. 當迴圈進行迴圈時,遊戲世界的狀態會更新,不論是否有播放程式輸入。As the loop iterates, the game world's state is updated, with or without player input. 這可讓您順暢地顯示所計算的動畫和行為。This allows the calculated animations and behaviors to be displayed smoothly. 假設我們只有一個水的簡單場景,只要玩家按下按鈕就會移動。Imagine if we had a simple scene of water that moved only when the player pressed a button. 這並不切合實際,好的遊戲隨時都有流暢且流暢的外觀。That wouldn't be realistic; a good game looks smooth and fluid all the time.

回想一下如上述 GameMain:: Run所示的範例遊戲迴圈。Recall the sample game's loop as shown above in GameMain::Run. 如果遊戲的主視窗是可見的,而未貼齊或停用,則遊戲會繼續更新並轉譯該更新的結果。If the game's main window is visible, and isn't snapped or deactivated, then the game continues to update and render the results of that update. 我們接著檢查的 GameRenderer:: Render 方法會呈現該狀態的標記法。The GameRenderer::Render method we examine next renders a representation of that state. 這會在呼叫 GameMain:: update之後立即完成,其中包括用來更新狀態的 Simple3DGame:: RunGame ,如上一節中所述。This is done immediately after a call to GameMain::Update, which includes Simple3DGame::RunGame to update states, as discussed in the previous section.

GameRenderer:: Render 繪製3d 世界的投影,然後在其上方繪製 Direct2D 重迭。GameRenderer::Render draws the projection of the 3D world, and then draws the Direct2D overlay on top of it. 完成時,它會顯示最後的交換鏈結,包含結合的顯示緩衝區。When completed, it presents the final swap chain with the combined buffers for display.

注意

範例遊戲的 Direct2D 重迭有兩種狀態 — ,其中的遊戲顯示包含 [暫停] 功能表點陣圖的遊戲資訊重迭,另一個則是遊戲顯示十字線以及觸控線移動外觀控制器的矩形。There are two states for the sample game's Direct2D overlay—one where the game displays the game info overlay that contains the bitmap for the pause menu, and one where the game displays the crosshairs along with the rectangles for the touchscreen move-look controller. 分數文字會同時在這兩種狀態繪製。The score text is drawn in both states. 如需詳細資訊,請參閱轉譯架構 I:轉譯簡介For more information, see Rendering framework I: Intro to rendering.

GameRenderer:: Render 方法The GameRenderer::Render method

void GameRenderer::Render()
{
    bool stereoEnabled{ m_deviceResources->GetStereoState() };

    auto d3dContext{ m_deviceResources->GetD3DDeviceContext() };
    auto d2dContext{ m_deviceResources->GetD2DDeviceContext() };

    ...
        if (m_game != nullptr && m_gameResourcesLoaded && m_levelResourcesLoaded)
        {
            // This section is only used after the game state has been initialized and all device
            // resources needed for the game have been created and associated with the game objects.
            ...
            for (auto&& object : m_game->RenderObjects())
            {
                object->Render(d3dContext, m_constantBufferChangesEveryPrim.get());
            }
        }

        d3dContext->BeginEventInt(L"D2D BeginDraw", 1);
        d2dContext->BeginDraw();

        // To handle the swapchain being pre-rotated, set the D2D transformation to include it.
        d2dContext->SetTransform(m_deviceResources->GetOrientationTransform2D());

        if (m_game != nullptr && m_gameResourcesLoaded)
        {
            // This is only used after the game state has been initialized.
            m_gameHud.Render(m_game);
        }

        if (m_gameInfoOverlay.Visible())
        {
            d2dContext->DrawBitmap(
                m_gameInfoOverlay.Bitmap(),
                m_gameInfoOverlayRect
                );
        }
        ...
    }
}

Simple3DGame 類別The Simple3DGame class

這些是 Simple3DGame 類別所定義的方法和資料成員。These are the methods and data members that are defined by the Simple3DGame class.

成員函數Member functions

Simple3DGame所定義的公用成員函式包含下列各項。Public member functions defined by Simple3DGame include the ones below.

  • 初始化Initialize. 設定全域變數的起始值,並初始化遊戲物件。Sets the starting values of the global variables, and initializes the game objects. 這會在 [ 初始化並啟動遊戲 ] 一節中討論。This is covered in the Initialize and start the game section.
  • LoadGameLoadGame. 初始化新的層級,並開始載入它。Initializes a new level, and starts loading it.
  • LoadLevelAsyncLoadLevelAsync. 初始化層級的協同程式,然後再叫用轉譯器上的另一個協同程式,以載入裝置特定層級的資源。A coroutine that initializes the level, and then invokes another coroutine on the renderer to load the device-specific level resources. 這個方法在另一個執行緒中執行;因此,從這個執行緒只能呼叫 ID3D11Device 方法 (與 ID3D11DeviceContext 方法相反)。This method runs in a separate thread; as a result, only ID3D11Device methods (as opposed to ID3D11DeviceContext methods) can be called from this thread. 任何裝置內容方法都是在 FinalizeLoadLevel 方法中呼叫的。Any device context methods are called in the FinalizeLoadLevel method. 如果您不熟悉非同步程式設計,請參閱 使用 c + +/WinRT 的並行和非同步作業If you're new to asynchronous programming, then see Concurrency and asynchronous operations with C++/WinRT.
  • FinalizeLoadLevelFinalizeLoadLevel. 在主執行緒上完成載入關卡時需要完成的所有工作。Completes any work for level loading that needs to be done on the main thread. 這包括任何呼叫 Direct3D 11 裝置內容 (ID3D11DeviceContext) 方法。This includes any calls to Direct3D 11 device context (ID3D11DeviceContext) methods.
  • StartLevelStartLevel. 開始新層級的遊戲。Starts the gameplay for a new level.
  • PauseGamePauseGame. 暫停遊戲。Pauses the game.
  • RunGameRunGame. 反覆執行遊戲迴圈。Runs an iteration of the game loop. 如果遊戲狀態為 Active,那麼每次反覆執行遊戲迴圈時就會從 App::Update 呼叫它一次。It's called from App::Update one time every iteration of the game loop if the game state is Active.
  • OnSuspendingOnResumingOnSuspending and OnResuming. 分別暫停/繼續遊戲的音訊。Suspend/resume the game's audio, respectively.

以下是私用成員函式。Here are the private member functions.

  • LoadSavedStateSaveStateLoadSavedState and SaveState. 分別載入/儲存遊戲的目前狀態。Load/save the current state of the game, respectively.
  • LoadHighScoreSaveHighScoreLoadHighScore and SaveHighScore. 分別在遊戲中載入/儲存高分。Load/save the high score across games, respectively.
  • InitializeAmmoInitializeAmmo. 為每一輪的開始,將做為子彈的每個球體物件狀態重設回它的原始狀態。Resets the state of each sphere object used as ammunition back to its original state for the beginning of each round.
  • UpdateDynamicsUpdateDynamics. 這是很重要的方法,因為它會根據現成的動畫常式、物理和控制項輸入來更新所有遊戲物件。This is an important method because it updates all the game objects based on canned animation routines, physics, and control input. 這是定義遊戲的互動核心。This is the heart of the interactivity that defines the game. 這會在「 更新遊戲世界 」一節中討論。This is covered in the Update the game world section.

其他公用方法為屬性存取子,可將遊戲和覆迭特定資訊傳回給應用程式架構以供顯示。The other public methods are property accessor that return gameplay- and overlay-specific information to the app framework for display.

資料成員Data members

當遊戲迴圈執行時,會更新這些物件。These objects are updated as the game loop runs.

  • MoveLookController 物件。MoveLookController object. 表示播放玩家輸入。Represents the player input. 如需詳細資訊,請參閱新增控制項For more information, see Adding controls.
  • GameRenderer 物件。GameRenderer object. 代表 Direct3D 11 轉譯器,其會處理所有裝置特定物件和其轉譯。Represents a Direct3D 11 renderer, which handles all the device-specific objects and their rendering. 如需詳細資訊,請參閱轉譯 架構 IFor more information, see Rendering framework I.
  • 音訊 物件。Audio object. 控制遊戲的音訊播放。Controls the audio playback for the game. 如需詳細資訊,請參閱 新增音效For more information, see Adding sound.

其餘的遊戲變數包含基本專案清單、其各自的遊戲中數量,以及遊戲播放特定的資料和條件約束。The rest of the game variables contain the lists of the primitives, and their respective in-game amounts, and game play specific data and constraints.

後續步驟Next steps

我們還在討論實際的轉譯引擎如何對 — 更新的基本專案Render的轉譯方法進行呼叫,以在您的螢幕上變成圖元。We have yet to talk about the actual rendering engine—how calls to the Render methods on the updated primitives get turned into pixels on your screen. 這些層面涵蓋于兩個部分 — :轉譯架構 I:轉譯和轉譯架構 II 的簡介:遊戲轉譯。Those aspects are covered in two parts—Rendering framework I: Intro to rendering and Rendering framework II: Game rendering. 如果您對玩家控制項如何更新遊戲狀態感興趣,請參閱 新增控制項If you're more interested in how the player controls update the game state, then see Adding controls.