SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
電子工程系應 用 電 子 組
電 腦 遊 戲 設 計 組
XNA4遊戲程式框架
吳錫修
October 19, 2015
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 解析XNA遊戲方案內容
 XNA Content Pipeline
 XNA遊戲程式基本架構
 Game類別
 GameComponent類別
 DrawableGameComponent類別
主題
2
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 專案範本選擇XNA Game Studio 4.0
 專案類型選擇Windows Games (4.0)
新增XNA專案
3
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 方案內含一個程式專案及一個內容資源專案
解析XNA方案
4
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
內容資源專案 1/2
5
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 AudioImporters用來讀入音效檔案
 EffectImporter用來讀入.fx特效檔案
 FBXImporter用來讀入.fbx格式的3D模型
 Ximporter用來讀入.x格式的3D模型
 TextureImporter用來讀入2D圖形檔,支援以下格式
.bmp、.dds、.dib、.hdr、.jpg、.pfm、.png、.ppm、.tga
 VideoImporter用來讀入視訊檔
內容資源專案 2/2
6
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 資源檔案在專案設計期間經由輸入器(Importer)、內容處理器
(Content Processor)、內容編譯器(Content Compiler)處理,產
生.xnb的二進位資源檔,以便執行時期使用內容載入器(Content
Loader)快速載入資源
XNA Content Pipeline
7
圖片來源:http://xna.gamedev.ru/articles/ContentPipelineOverview
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
程式專案
8
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
using System;
namespace WindowsGame1
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (Game1 game = new Game1()) //建立遊戲物件
{
game.Run(); //執行遊戲
}
}
}
#endif
}
Program.cs
9
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
XNA遊戲程式流程
10
遊戲初始化
載入資源(2D圖形、3D模型、音效檔字型等)
得到使用者的輸入(鍵盤、滑鼠…)
邏輯檢查及狀態更新(移動、碰撞、AI、結束…)
繪出 (圖形產出、聲音…)
釋放資源
遊
戲
迴
圈
Game建構元:一般初始化
Initialize()遊戲初始化
LoadContent()
Update(GameTime gameTime)
Draw(GameTime gameTime)
UnloadContent()
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 遊戲迴圈內定每秒執行60次
 this.TargetElaspedTime = new TimeSpan(0,0,0,0,33); //改為1/30秒
game.Run() 的執行流程
11
Initialize()
LoadContent()
Update(GameTime gametime)
Draw(GameTime gameTime)
UnloadContent()
遊戲迴圈
一次性作業
一次性作業
一次性作業
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace WindowsGame1
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics; // 繪圖卡管理物件
SpriteBatch spriteBatch; // 2D圖形繪出物件
}
...
};
Game1.cs 1/5
12
引用XNA命名空間
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; // 指定內容資源之目錄名稱
}
/// <summary>
///遊戲初始化作業
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
Game1.cs 2/5
13
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
/// <summary>
/// 資源載入作業,遊戲執行時LoadContent只會被執行一次
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// 釋放資源作業,遊戲執行時UnloadContent只會被執行一次
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
Game1.cs 3/5
14
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
/// <summary>
/// 遊戲世界更新作業,例如檢查碰撞、收集輸入、撥放音效
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// 預設按下GamePad的Back鍵結束遊戲
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
Game1.cs 4/5
15
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
/// <summary>
/// 繪圖更新作業
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue); //預設底色(矢車菊藍)
// TODO: Add your drawing code here
base.Draw(gameTime);
}
Game1.cs 5/5
16
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
1. 新增一個XNA 4.0專案,專案名稱XNALabI
2. 修改Game1(),設定視窗標題、顯示滑鼠游標、並重設畫面更新速
率為30Hz
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// TODO: Add your initialization logic here
this.IsMouseVisible = true; // 顯示滑鼠游標
this.Window.AllowUserResizing = true; // 允許視窗縮放
graphics.PreferredBackBufferWidth = 400; //視窗的預設寬
graphics.PreferredBackBufferHeight = 300; //視窗的預設高
this.Window.Title = “學號 - 個人姓名"; // 視窗標題
this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 33); // 每秒更新 30 個畫面
}
實作練習(一) 1/2
17
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
3. 修改Update(),當按下Esc鍵時結束程式
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
KeyboardState newState;
newState = Keyboard.GetState();
if (newState.IsKeyDown(Keys.Escape)) this.Exit(); // Esc鍵結束程式
// TODO: Add your update logic here
base.Update(gameTime);
}
4. 編譯執行XNALabI
實作練習(一) 2/2
18
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
1. 開啟XNALabI方案,將Cross4.png加到XNALabIContent
2. 在Game1類別新增資料成員,記錄顏色值及
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
byte R = 0, G = 0, B = 0; // 紅、綠、藍三原色初始色
Texture2D bg_frame;
…
}
3. 修改LoadContent(),載入圖檔資源
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
bg_frame = this.Content.Load<Texture2D>("Cross4"); // 載入底圖
}
實作練習(二) 1/3
19
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
4. 修改Update(),依據滑鼠游標位置設定顏色值
protected override void Update(GameTime gameTime)
{
…
// TODO: Add your update logic here
MouseState mouse = Mouse.GetState(); // 取得滑鼠狀態
if (mouse.X > graphics.PreferredBackBufferWidth / 2) // 超過螢幕寬的一半
R = 255;
else
R = 0;
if (mouse.Y > graphics.PreferredBackBufferHeight / 2) // 超過螢幕高的一半
G = 255;
else
G = 0;
base.Update(gameTime);
}
實作練習(二) 2/3
20
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
5. 修改Draw(),更新背景顏色
protected override void Draw(GameTime gameTime)
{
// TODO: Add your drawing code here
graphics.GraphicsDevice.Clear(new Color(R, G, B));
spriteBatch.Begin();
spriteBatch.Draw(bg_frame,
new Rectangle(0, 0, this.graphics.PreferredBackBufferWidth,
this.graphics.PreferredBackBufferHeight),
Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
6. 編譯執行XNALabI
實作練習(二) 3/3
21
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 遊戲程式流程包括:初始化、載入資源、取得使用者輸入、邏輯更
新、更新畫面、收尾結束
 Microsoft.Xna.Framework.Game類別將視窗的產生、繪圖、聲音
和輸入的初始化、遊戲程式流程等細節隱藏包裹起來,讓程式設計
師省掉諸多困擾與麻煩
 GraphicsDeviceManager物件代表一個可以管理、取得及設定繪圖
卡的總管
 SpriteBatch物件可以設定2D圖形繪出資料後,以批次方式處理
 透過TargetElapsedTime屬性值調整遊戲畫面更新率
重點回顧 1/2
22
shapethefuture
電子工程系
應 用 電 子 組
電 腦 遊 戲 設 計 組
 GamePad.GetState()取得遊戲搖桿狀態
 Mouse.GetState()取得滑鼠狀態
 Keyboard.GetState()取得鍵盤狀態
 視窗寬度與高度可分別由GraphicsDeviceManager物件之
PreferredBackBufferWidth及PreferredBackBufferHeight屬性來
取得或設定
重點回顧 2/2
23

Weitere ähnliche Inhalte

Andere mochten auch

使用CocoonJS發佈Construct 2專案到Android手機
使用CocoonJS發佈Construct 2專案到Android手機使用CocoonJS發佈Construct 2專案到Android手機
使用CocoonJS發佈Construct 2專案到Android手機吳錫修 (ShyiShiou Wu)
 
Arduino Yún使用sd card儲存監測資料
Arduino Yún使用sd card儲存監測資料Arduino Yún使用sd card儲存監測資料
Arduino Yún使用sd card儲存監測資料吳錫修 (ShyiShiou Wu)
 
機器人齊步走 V4 m_bot_mblock
機器人齊步走 V4 m_bot_mblock機器人齊步走 V4 m_bot_mblock
機器人齊步走 V4 m_bot_mblock信仁 邱
 
20142015機器人競賽資訊
20142015機器人競賽資訊20142015機器人競賽資訊
20142015機器人競賽資訊信仁 邱
 
2014探奇NXT機器人 wro v1
2014探奇NXT機器人 wro v12014探奇NXT機器人 wro v1
2014探奇NXT機器人 wro v1信仁 邱
 
2015 wro比賽資訊
2015 wro比賽資訊2015 wro比賽資訊
2015 wro比賽資訊信仁 邱
 

Andere mochten auch (20)

S4 a sensor board
S4 a sensor boardS4 a sensor board
S4 a sensor board
 
使用CocoonJS發佈Construct 2專案到Android手機
使用CocoonJS發佈Construct 2專案到Android手機使用CocoonJS發佈Construct 2專案到Android手機
使用CocoonJS發佈Construct 2專案到Android手機
 
Construct2簡介
Construct2簡介Construct2簡介
Construct2簡介
 
使用console訊息操作Arduino Yún IO
使用console訊息操作Arduino Yún IO使用console訊息操作Arduino Yún IO
使用console訊息操作Arduino Yún IO
 
Construct 2事件表作業
Construct 2事件表作業Construct 2事件表作業
Construct 2事件表作業
 
Arduino Yún使用linino process
Arduino Yún使用linino processArduino Yún使用linino process
Arduino Yún使用linino process
 
Construct 2 Physics behavior
Construct 2 Physics behaviorConstruct 2 Physics behavior
Construct 2 Physics behavior
 
Arduino Yún console連線
Arduino Yún console連線Arduino Yún console連線
Arduino Yún console連線
 
Arduino Yún使用sd card儲存監測資料
Arduino Yún使用sd card儲存監測資料Arduino Yún使用sd card儲存監測資料
Arduino Yún使用sd card儲存監測資料
 
AMA 中級術科實作 I
AMA 中級術科實作 IAMA 中級術科實作 I
AMA 中級術科實作 I
 
8direction behavior
8direction behavior8direction behavior
8direction behavior
 
機器人齊步走 V4 m_bot_mblock
機器人齊步走 V4 m_bot_mblock機器人齊步走 V4 m_bot_mblock
機器人齊步走 V4 m_bot_mblock
 
20142015機器人競賽資訊
20142015機器人競賽資訊20142015機器人競賽資訊
20142015機器人競賽資訊
 
2014探奇NXT機器人 wro v1
2014探奇NXT機器人 wro v12014探奇NXT機器人 wro v1
2014探奇NXT機器人 wro v1
 
Construct 2的Particles物件
Construct 2的Particles物件Construct 2的Particles物件
Construct 2的Particles物件
 
AMA 中級術科實作III
AMA 中級術科實作IIIAMA 中級術科實作III
AMA 中級術科實作III
 
AMA 中級術科實作IV
AMA 中級術科實作IVAMA 中級術科實作IV
AMA 中級術科實作IV
 
2015 wro比賽資訊
2015 wro比賽資訊2015 wro比賽資訊
2015 wro比賽資訊
 
AMA 中級術科實作II
AMA 中級術科實作IIAMA 中級術科實作II
AMA 中級術科實作II
 
Avgminmax223
Avgminmax223Avgminmax223
Avgminmax223
 

Ähnlich wie XNA遊戲程式框架

09 creating windows phone game with cocos2d-xna
09   creating windows phone game with cocos2d-xna09   creating windows phone game with cocos2d-xna
09 creating windows phone game with cocos2d-xna乐费 胡
 
Game development using monogame
Game development using monogameGame development using monogame
Game development using monogamePower Wu
 
基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册Zhen Li
 
Behind Tetris5
Behind Tetris5Behind Tetris5
Behind Tetris5Junwen Sun
 
component based html5 game engine
component based html5 game enginecomponent based html5 game engine
component based html5 game enginehbbalfred
 
Introduction to corona sdk
Introduction to corona sdkIntroduction to corona sdk
Introduction to corona sdk馬 萬圳
 
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試吳錫修 (ShyiShiou Wu)
 
LinkIt Smart 7688程式開發
LinkIt Smart 7688程式開發LinkIt Smart 7688程式開發
LinkIt Smart 7688程式開發Wei-Tsung Su
 
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台Shengyou Fan
 
Api Code Pack For Net Framework
Api Code Pack For Net FrameworkApi Code Pack For Net Framework
Api Code Pack For Net FrameworkChui-Wen Chiu
 
Spm5 data analysis of fmri (chinese edition)
Spm5 data analysis of fmri (chinese edition)Spm5 data analysis of fmri (chinese edition)
Spm5 data analysis of fmri (chinese edition)Hanna LU
 
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1Solitaire with Greenfoot #1
Solitaire with Greenfoot #1imacat .
 
R統計軟體簡介
R統計軟體簡介R統計軟體簡介
R統計軟體簡介Person Lin
 
Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01imacat .
 
Windows Mobile 6 遊戲開發入門
Windows Mobile 6 遊戲開發入門Windows Mobile 6 遊戲開發入門
Windows Mobile 6 遊戲開發入門Chui-Wen Chiu
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control ManagementWen-Shih Chao
 
Unity脚本入门
Unity脚本入门Unity脚本入门
Unity脚本入门seenen
 
先用再学 - 借助 Xna 快速开发游戏原型
先用再学  - 借助 Xna 快速开发游戏原型先用再学  - 借助 Xna 快速开发游戏原型
先用再学 - 借助 Xna 快速开发游戏原型勇浩 赖
 

Ähnlich wie XNA遊戲程式框架 (20)

Unity遊戲程式設計- Unity基礎指引
Unity遊戲程式設計- Unity基礎指引Unity遊戲程式設計- Unity基礎指引
Unity遊戲程式設計- Unity基礎指引
 
09 creating windows phone game with cocos2d-xna
09   creating windows phone game with cocos2d-xna09   creating windows phone game with cocos2d-xna
09 creating windows phone game with cocos2d-xna
 
Game development using monogame
Game development using monogameGame development using monogame
Game development using monogame
 
基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册
 
Behind Tetris5
Behind Tetris5Behind Tetris5
Behind Tetris5
 
component based html5 game engine
component based html5 game enginecomponent based html5 game engine
component based html5 game engine
 
Introduction to corona sdk
Introduction to corona sdkIntroduction to corona sdk
Introduction to corona sdk
 
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試
建立PHP & MySQL應用程式開發環境 - XAMPP安裝與測試
 
LinkIt Smart 7688程式開發
LinkIt Smart 7688程式開發LinkIt Smart 7688程式開發
LinkIt Smart 7688程式開發
 
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
 
Api Code Pack For Net Framework
Api Code Pack For Net FrameworkApi Code Pack For Net Framework
Api Code Pack For Net Framework
 
Spm5 data analysis of fmri (chinese edition)
Spm5 data analysis of fmri (chinese edition)Spm5 data analysis of fmri (chinese edition)
Spm5 data analysis of fmri (chinese edition)
 
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1Solitaire with Greenfoot #1
Solitaire with Greenfoot #1
 
R統計軟體簡介
R統計軟體簡介R統計軟體簡介
R統計軟體簡介
 
Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01Object-Oriented Programming Design with Greenfoot 01
Object-Oriented Programming Design with Greenfoot 01
 
Windows Mobile 6 遊戲開發入門
Windows Mobile 6 遊戲開發入門Windows Mobile 6 遊戲開發入門
Windows Mobile 6 遊戲開發入門
 
漫談 Source Control Management
漫談 Source Control Management漫談 Source Control Management
漫談 Source Control Management
 
Unity脚本入门
Unity脚本入门Unity脚本入门
Unity脚本入门
 
Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
先用再学 - 借助 Xna 快速开发游戏原型
先用再学  - 借助 Xna 快速开发游戏原型先用再学  - 借助 Xna 快速开发游戏原型
先用再学 - 借助 Xna 快速开发游戏原型
 

Mehr von 吳錫修 (ShyiShiou Wu)

Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲吳錫修 (ShyiShiou Wu)
 
Unity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理IUnity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理I吳錫修 (ShyiShiou Wu)
 
Unity遊戲設計- 2D動畫製作及應用
Unity遊戲設計-  2D動畫製作及應用Unity遊戲設計-  2D動畫製作及應用
Unity遊戲設計- 2D動畫製作及應用吳錫修 (ShyiShiou Wu)
 

Mehr von 吳錫修 (ShyiShiou Wu) (20)

Vuforia AR影片程式設計
Vuforia AR影片程式設計Vuforia AR影片程式設計
Vuforia AR影片程式設計
 
micro:bit亮度感測應用
micro:bit亮度感測應用micro:bit亮度感測應用
micro:bit亮度感測應用
 
Vuforia AR 同時追踨多張辨識圖
Vuforia AR同時追踨多張辨識圖Vuforia AR同時追踨多張辨識圖
Vuforia AR 同時追踨多張辨識圖
 
micro:bit開關控制應用
micro:bit開關控制應用micro:bit開關控制應用
micro:bit開關控制應用
 
Vuforia AR 應用程式設計入門
Vuforia AR應用程式設計入門Vuforia AR應用程式設計入門
Vuforia AR 應用程式設計入門
 
Vuforia AR 應用程式準備作業
Vuforia AR應用程式準備作業Vuforia AR應用程式準備作業
Vuforia AR 應用程式準備作業
 
micro:bit LED顯示控制
micro:bit LED顯示控制micro:bit LED顯示控制
micro:bit LED顯示控制
 
IDE for micro:bit
IDE for micro:bitIDE for micro:bit
IDE for micro:bit
 
Microbit 1 introduction
Microbit 1 introductionMicrobit 1 introduction
Microbit 1 introduction
 
Arduino overview
Arduino overviewArduino overview
Arduino overview
 
使用Makeblock App學習mBot程式設計
使用Makeblock App學習mBot程式設計使用Makeblock App學習mBot程式設計
使用Makeblock App學習mBot程式設計
 
使用M部落App學習mBot程式設計
使用M部落App學習mBot程式設計使用M部落App學習mBot程式設計
使用M部落App學習mBot程式設計
 
nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論
 
nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲
 
Unity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理IUnity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理I
 
Python與Ardinio整合應用
Python與Ardinio整合應用Python與Ardinio整合應用
Python與Ardinio整合應用
 
mBlock積木式設計程式
mBlock積木式設計程式mBlock積木式設計程式
mBlock積木式設計程式
 
Arduino程式除錯
Arduino程式除錯Arduino程式除錯
Arduino程式除錯
 
Unity遊戲設計- 2D動畫製作及應用
Unity遊戲設計-  2D動畫製作及應用Unity遊戲設計-  2D動畫製作及應用
Unity遊戲設計- 2D動畫製作及應用
 

Kürzlich hochgeladen

SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptx
SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptxSymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptx
SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptxNCU MCL
 
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...Jamie (Taka) Wang
 
20220113_product_day copy.pdf20220113_product_day copy.pdf
20220113_product_day copy.pdf20220113_product_day copy.pdf20220113_product_day copy.pdf20220113_product_day copy.pdf
20220113_product_day copy.pdf20220113_product_day copy.pdfJamie (Taka) Wang
 
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdfJamie (Taka) Wang
 
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdfJamie (Taka) Wang
 
20200607_insight_sync.pdf20200607_insight_sync.pdf
20200607_insight_sync.pdf20200607_insight_sync.pdf20200607_insight_sync.pdf20200607_insight_sync.pdf
20200607_insight_sync.pdf20200607_insight_sync.pdfJamie (Taka) Wang
 
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptxNCU MCL
 
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdfJamie (Taka) Wang
 
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdfJamie (Taka) Wang
 
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptxNCU MCL
 
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdfJamie (Taka) Wang
 
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptxNCU MCL
 
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdfJamie (Taka) Wang
 
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...Jamie (Taka) Wang
 
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】黑客 接单【TG/微信qoqoqdqd】
 
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptx
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptxSymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptx
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptxNCU MCL
 
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptxNCU MCL
 

Kürzlich hochgeladen (17)

SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptx
SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptxSymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptx
SymPy 在微積分上的應用_4.pptx SymPy 在微積分上的應用_4.pptx
 
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...
20200429_01_software_v8.pdf20200429_01_software_v8.pdf20200429_01_software_v8...
 
20220113_product_day copy.pdf20220113_product_day copy.pdf
20220113_product_day copy.pdf20220113_product_day copy.pdf20220113_product_day copy.pdf20220113_product_day copy.pdf
20220113_product_day copy.pdf20220113_product_day copy.pdf
 
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf
20210105_量產技轉.pdf20210105_量產技轉.pdf20210105_量產技轉.pdf
 
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf
20200808自營電商平台策略討論20200808自營電商平台策略討論_v1.pdf
 
20200607_insight_sync.pdf20200607_insight_sync.pdf
20200607_insight_sync.pdf20200607_insight_sync.pdf20200607_insight_sync.pdf20200607_insight_sync.pdf
20200607_insight_sync.pdf20200607_insight_sync.pdf
 
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx
函數畫圖_習題5.pptx 函數畫圖_習題5.pptx 函數畫圖_習題5.pptx
 
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf
20200602_insight_business_plan_3.pdf20200602_insight_business_plan_3.pdf
 
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf
20200427_02_hardware_v3.pdf20200427_02_hardware_v3.pdf
 
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx
函數畫圖_習題6.pptx 函數畫圖_習題6.pptx 函數畫圖_習題6.pptx
 
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf
20200606_insight_Ignition.pdf20200606_insight_Ignition.pdf
 
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx
函數微分_習題4.pptx 函數微分_習題4.pptx 函數微分_習題4.pptx
 
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf
20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf20200429_03_ec_v8.pdf
 
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...
20200727_Insight workstation A1 plus 測試報告.pdf20200727_Insight workstation A1 ...
 
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】
买假和真英国驾驶执照买了假的英国驾照,那跟真的有什么区别吗?买假和真正的澳大利亚驾驶执照【微信qoqoqdqd】
 
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptx
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptxSymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptx
SymPy 在微積分上的應用_5.pptx SymPy 在微積分上的應用_5.pptx
 
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx
函數畫圖_習題7.pptx 函數畫圖_習題7.pptx 函數畫圖_習題7.pptx
 

XNA遊戲程式框架

  • 1. 電子工程系應 用 電 子 組 電 腦 遊 戲 設 計 組 XNA4遊戲程式框架 吳錫修 October 19, 2015
  • 2. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  解析XNA遊戲方案內容  XNA Content Pipeline  XNA遊戲程式基本架構  Game類別  GameComponent類別  DrawableGameComponent類別 主題 2
  • 3. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  專案範本選擇XNA Game Studio 4.0  專案類型選擇Windows Games (4.0) 新增XNA專案 3
  • 4. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  方案內含一個程式專案及一個內容資源專案 解析XNA方案 4
  • 5. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 內容資源專案 1/2 5
  • 6. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  AudioImporters用來讀入音效檔案  EffectImporter用來讀入.fx特效檔案  FBXImporter用來讀入.fbx格式的3D模型  Ximporter用來讀入.x格式的3D模型  TextureImporter用來讀入2D圖形檔,支援以下格式 .bmp、.dds、.dib、.hdr、.jpg、.pfm、.png、.ppm、.tga  VideoImporter用來讀入視訊檔 內容資源專案 2/2 6
  • 7. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  資源檔案在專案設計期間經由輸入器(Importer)、內容處理器 (Content Processor)、內容編譯器(Content Compiler)處理,產 生.xnb的二進位資源檔,以便執行時期使用內容載入器(Content Loader)快速載入資源 XNA Content Pipeline 7 圖片來源:http://xna.gamedev.ru/articles/ContentPipelineOverview
  • 8. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 程式專案 8
  • 9. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 using System; namespace WindowsGame1 { #if WINDOWS || XBOX static class Program { /// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (Game1 game = new Game1()) //建立遊戲物件 { game.Run(); //執行遊戲 } } } #endif } Program.cs 9
  • 10. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 XNA遊戲程式流程 10 遊戲初始化 載入資源(2D圖形、3D模型、音效檔字型等) 得到使用者的輸入(鍵盤、滑鼠…) 邏輯檢查及狀態更新(移動、碰撞、AI、結束…) 繪出 (圖形產出、聲音…) 釋放資源 遊 戲 迴 圈 Game建構元:一般初始化 Initialize()遊戲初始化 LoadContent() Update(GameTime gameTime) Draw(GameTime gameTime) UnloadContent()
  • 11. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  遊戲迴圈內定每秒執行60次  this.TargetElaspedTime = new TimeSpan(0,0,0,0,33); //改為1/30秒 game.Run() 的執行流程 11 Initialize() LoadContent() Update(GameTime gametime) Draw(GameTime gameTime) UnloadContent() 遊戲迴圈 一次性作業 一次性作業 一次性作業
  • 12. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace WindowsGame1 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; // 繪圖卡管理物件 SpriteBatch spriteBatch; // 2D圖形繪出物件 } ... }; Game1.cs 1/5 12 引用XNA命名空間
  • 13. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // 指定內容資源之目錄名稱 } /// <summary> ///遊戲初始化作業 /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } Game1.cs 2/5 13
  • 14. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 /// <summary> /// 資源載入作業,遊戲執行時LoadContent只會被執行一次 /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here } /// <summary> /// 釋放資源作業,遊戲執行時UnloadContent只會被執行一次 /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } Game1.cs 3/5 14
  • 15. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 /// <summary> /// 遊戲世界更新作業,例如檢查碰撞、收集輸入、撥放音效 /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // 預設按下GamePad的Back鍵結束遊戲 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here base.Update(gameTime); } Game1.cs 4/5 15
  • 16. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 /// <summary> /// 繪圖更新作業 /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); //預設底色(矢車菊藍) // TODO: Add your drawing code here base.Draw(gameTime); } Game1.cs 5/5 16
  • 17. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 1. 新增一個XNA 4.0專案,專案名稱XNALabI 2. 修改Game1(),設定視窗標題、顯示滑鼠游標、並重設畫面更新速 率為30Hz public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // TODO: Add your initialization logic here this.IsMouseVisible = true; // 顯示滑鼠游標 this.Window.AllowUserResizing = true; // 允許視窗縮放 graphics.PreferredBackBufferWidth = 400; //視窗的預設寬 graphics.PreferredBackBufferHeight = 300; //視窗的預設高 this.Window.Title = “學號 - 個人姓名"; // 視窗標題 this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 33); // 每秒更新 30 個畫面 } 實作練習(一) 1/2 17
  • 18. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 3. 修改Update(),當按下Esc鍵時結束程式 protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); KeyboardState newState; newState = Keyboard.GetState(); if (newState.IsKeyDown(Keys.Escape)) this.Exit(); // Esc鍵結束程式 // TODO: Add your update logic here base.Update(gameTime); } 4. 編譯執行XNALabI 實作練習(一) 2/2 18
  • 19. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 1. 開啟XNALabI方案,將Cross4.png加到XNALabIContent 2. 在Game1類別新增資料成員,記錄顏色值及 public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; byte R = 0, G = 0, B = 0; // 紅、綠、藍三原色初始色 Texture2D bg_frame; … } 3. 修改LoadContent(),載入圖檔資源 protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here bg_frame = this.Content.Load<Texture2D>("Cross4"); // 載入底圖 } 實作練習(二) 1/3 19
  • 20. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 4. 修改Update(),依據滑鼠游標位置設定顏色值 protected override void Update(GameTime gameTime) { … // TODO: Add your update logic here MouseState mouse = Mouse.GetState(); // 取得滑鼠狀態 if (mouse.X > graphics.PreferredBackBufferWidth / 2) // 超過螢幕寬的一半 R = 255; else R = 0; if (mouse.Y > graphics.PreferredBackBufferHeight / 2) // 超過螢幕高的一半 G = 255; else G = 0; base.Update(gameTime); } 實作練習(二) 2/3 20
  • 21. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組 5. 修改Draw(),更新背景顏色 protected override void Draw(GameTime gameTime) { // TODO: Add your drawing code here graphics.GraphicsDevice.Clear(new Color(R, G, B)); spriteBatch.Begin(); spriteBatch.Draw(bg_frame, new Rectangle(0, 0, this.graphics.PreferredBackBufferWidth, this.graphics.PreferredBackBufferHeight), Color.White); spriteBatch.End(); base.Draw(gameTime); } 6. 編譯執行XNALabI 實作練習(二) 3/3 21
  • 22. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  遊戲程式流程包括:初始化、載入資源、取得使用者輸入、邏輯更 新、更新畫面、收尾結束  Microsoft.Xna.Framework.Game類別將視窗的產生、繪圖、聲音 和輸入的初始化、遊戲程式流程等細節隱藏包裹起來,讓程式設計 師省掉諸多困擾與麻煩  GraphicsDeviceManager物件代表一個可以管理、取得及設定繪圖 卡的總管  SpriteBatch物件可以設定2D圖形繪出資料後,以批次方式處理  透過TargetElapsedTime屬性值調整遊戲畫面更新率 重點回顧 1/2 22
  • 23. shapethefuture 電子工程系 應 用 電 子 組 電 腦 遊 戲 設 計 組  GamePad.GetState()取得遊戲搖桿狀態  Mouse.GetState()取得滑鼠狀態  Keyboard.GetState()取得鍵盤狀態  視窗寬度與高度可分別由GraphicsDeviceManager物件之 PreferredBackBufferWidth及PreferredBackBufferHeight屬性來 取得或設定 重點回顧 2/2 23