Animation (動畫) 靜宜大學資工系 蔡奇偉 副教授 © 2011. 大綱 Introduction Game Loop Motion Animation Game Components 範例 參考資料.

Slides:



Advertisements
Similar presentations
FCU, Department of ECE, IC Design Research Lab. TEL: # 4945 Pre-SIm , Post-Sim.
Advertisements

McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
Section 1.2 Describing Distributions with Numbers 用數字描述分配.
第二章 太陽能電池的基本原理 及其結構 2-1 太陽能電池的基本原理 2-2 太陽能電池的基本結構 2-3 太陽能電池的製作.
教案課程片頭介紹 教案課程片頭是以圖片透過 Powerpoint 之動畫設 計功能轉變而成的動畫形式所呈現出來的影片, 目的是要讓老師們的課程顯得更加活潑、生動、 有趣,以往傳統的做法大部分都是以文字或投影 片的方式呈現,後來加以改良成為動畫呈現方式, 使得學生在複習課程方面能更加淺顯易懂、激發 出更多學習的興趣與樂趣。
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1 第一章 Word 的基本觀念 內容概要: Word 的特色 啟動與離開 Word 的方法 滑鼠游標與外型的介紹 基本操作 Word 視窗法則 使用 Word 遭遇問題時, 應如何利用軟體特 性而獲得輔助解說.
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
五小專案 黃詩晴 章乃云. 目錄 計算機 智慧盤 拼圖 記憶大挑戰 數學題庫 心得 參考文獻.
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
Chapter 2 聯立線性方程式與矩陣 緒言 線性方程式組 (systems of linear equations) 出現 在多數線性模式 (linear model) 中。根據以往解 題的經驗,讀者們也許已發現方程式的解僅與 該方程式的係數有關,求解的過程也僅與係數 的運算有關,只要係數間的相關位置不改變,
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
MATLAB 程式設計 第 11 章 多維陣列 多維陣列的定義 在 MATLAB 的資料型態中,向量可視為 一維陣列,矩陣可視二維陣列,對於維 度 (Dimensions) 超過 1 的陣列則均可視 為「多維陣列」 (Multidimesional Arrays , 簡稱 N-D Arrays)
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology 模糊控制設計使用 MATLAB 李達生.
JAVA 程式設計與資料結構 第十章 GUI Introdution III. File Chooser  File Chooser 是一個選擇檔案的圖形介面, 無論我們是要存檔還是要開啟檔案,使 用這個物件都會讓我們覺得容易且舒適。
© The McGraw-Hill Companies, Inc., 2008 第 6 章 製造流程的選擇與設計.
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
影像處理學習營 練習(四)製作影片 【下】 影像處理學習營 教師 吳清月. 製作影片 學習重點 一. 設定影片秒數。  加入音樂,與影片做結合。 三. 影片存檔方式之選擇  上傳到網路.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
第三部分:研究設計 ( 二): 研究工具的信效度 與研究效度 (第九章之第 306 頁 -308 頁;第四章)
3-3 使用幾何繪圖工具 Flash 的幾何繪圖工具包括線段工具 (Line Tool) 、橢圓形工具 (Oval Tool) 、多邊星形 工具 (Rectangle Tool) 3 種。這些工具畫出 來的幾何圖形包括了筆畫線條和填色區域, 將它們適當地組合加上有技巧地變形與配 色, 不但比鉛筆工具簡單,
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
基準特徵 基準面 基準座標系 基準點 基準線 基準軸 基準特徵顯示之控制. 基準特徵 基準面 基準座標系 基準點 基準線 基準軸 基準特徵顯示之控制.
第二章 供給與需求 中興大學會計學系 授課老師:簡立賢.
圖層的操作與管理 圖層的作用就如同一張張透明的賽璐璐片, 你可以將動畫中的每項物件, 放置在不同圖 層中, 圖層交疊就形成完整的畫面。在各圖 層中的物件, 做任何的移動或變化, 都不會 相互干擾, 所以當你編輯一個物件時, 只要 在物件所在的圖層進行操作, 將可大幅降低 製作過程的複雜度與難度。
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology MATLAB 操作與 系統動態模擬 SIMULINK 李達生.
各種線上電子資源的特異功能 SwetsWise 的 alert, TOC alert 與 Favorites 2003/4/28 修改.
CH 15- 元件可靠度之驗證  驗證方法  指數模式之可靠度驗證  韋式模式之可靠度驗證  對數常態模式之可靠度驗證  失效數為零時之可靠度估算  各種失效模式之應用.
資料庫程式設計與系統管理 SQL Server 2005 Express 第六章 進階資料庫設計.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
結構學(一) 第七次作業 97/05/15.
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
生產系統導論 生產系統簡介 績效衡量 現代工廠之特徵 管理機能.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
企二 A 管理程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 企二 A 管理程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
Feature Motion for Monocular Robot Navigation. 單視覺機器人 – 追蹤 (tracking) 最常見的機器人導航技術 特徵點特性(特別 匹配性 抗破壞性) 特徵點取得(區塊 尺度不變)
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
公用品.  該物品的數量不會因一人的消費而受到 影響,它可以同時地被多人享用。 角色分配  兩位同學當我的助手,負責:  其餘各人是投資者,每人擁有 $100 , 可以投資在兩種資產上。  記錄  計算  協助同學討論.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
Chapter 6 線性規劃 緒言 如何在有限的經濟資源下進行最有效的調配與 選用,以求發揮資源的最高效能。此問題愈來 愈受到重視,也就是以最低的代價,獲取最大 的效益。 茲列舉如下: – 決定緊急設備與人員的地點,使反應時間最短化。 – 決定飛機、飛行員、地勤人員的飛航最佳日程安排。
Chapter 3 Entropy : An Additional Balance Equation
Chapter 10 m-way 搜尋樹與B-Tree
本章重點 2-1 有序串列(Ordered List) 2-2 介紹陣列(array) 2-3 矩陣(matrix)的應用
Probability Distribution 機率分配 汪群超 12/12. 目的:產生具均等分配的數值 (Data) ,並以 『直方圖』的功能計算出數值在不同範圍內出現 的頻率,及繪製數值的分配圖,以反應出該 機率分配的特性。
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
冷凍空調自動控制 - 系統性能分析 李達生. Focusing here … 概論 自動控制理論發展 自控系統設計實例 Laplace Transform 冷凍空調自動控制 控制系統範例 控制元件作動原理 控制系統除錯 自動控制理論 系統穩定度分析 系統性能分析 PID Controller 自動控制實務.
連續隨機變數 連續變數:時間、分數、重量、……
: Wine trading in Gergovia ★★☆☆☆ 題組: Contest Volumes with Online Judge 題號: 11054: Wine trading in Gergovia 解題者:劉洙愷 解題日期: 2008 年 2 月 29 日 題意:在 Gergovia.
-Artificial Neural Network- Matlab操作介紹 -以類神經網路BPN Model為例
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
Microsoft Excel.
Regression 相關 –Cross table –Bivariate –Contingency Cofficient –Rank Correlation 簡單迴歸 多元迴歸.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
結構學 ( 一 ) 第八次作業 97/05/22. 題目一 題目一 (a) 先決定放鬆哪個束制,成為靜定結構 以支承 C 之水平反力為贅力,則 C 點滾支 承變成自由端,即形成靜定基元結構 C 點滿足變位諧和  Δ CH =0.
CH 14-可靠度工程之數學基礎 探討重點 失效時間之機率分配 指數模式之可靠度工程.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
XNA 4.0 簡介 靜宜大學資工系 蔡奇偉 副教授 © 大綱 XNA 簡介 XNA Framework XNA Build XNA Game Studio 建立 XNA 4 的專案 方案的目錄結構 XNA Game Studio 4.0 參考手冊 Hello, XNA XNA Game.
Presentation transcript:

Animation (動畫) 靜宜大學資工系 蔡奇偉 副教授 © 2011

大綱 Introduction Game Loop Motion Animation Game Components 範例 參考資料

簡介 動畫是由隨時間而改變的圖片所產生 2D 遊戲動畫可由下列三種技巧產生: Motion Animation Sprite Animation Motion + Sprite Animation

XNA Game Loop Initialize() LoadContent () Game quit? Draw () UnLoadContent () Y Update () N Exit

Fixed-Step Game Loops A fixed-step Game tries to call its Update method on the fixed interval specified in TargetElapsedTime. Setting Game.IsFixedTimeStep to true causes a Game to use a fixed-step game loop. A new XNA project uses a fixed-step game loop with a default TargetElapsedTime of 1/60th of a second. In a fixed-step game loop, Game calls Update once the TargetElapsedTime has elapsed. After Update is called, if it is not time to call Update again, Game calls Draw. After Draw is called, if it is not time to call Update again, Game idles until it is time to call Update.

If Update takes too long to process, Game sets IsRunningSlowly to true and calls Update again, without calling Draw in between. When an update runs longer than the TargetElapsedTime, Game responds by calling Update extra times and dropping the frames associated with those updates to catch up. This ensures that Update will have been called the expected number of times when the game loop catches up from a slowdown. You can check the value of IsRunningSlowly in your Update if you want to detect dropped frames and shorten your Update processing to compensate. You can reset the elapsed times by calling ResetElapsedTime.

Variable-Step Game Loops A variable-step game calls its Update and Draw methods in a continuous loop without regard to the TargetElapsedTime. Setting Game.IsFixedTimeStep to false causes a Game to use a variable-step game loop.

Animation and Timing Using a fixed step allows game logic to use the TargetElapsedTime as its basic unit of time and assume that Update will be called at that interval. Using a variable step requires the game logic and animation code to be based on ElapsedGameTime to ensure smooth gameplay. Because the Update method is called immediately after the previous frame is drawn, the time between calls to Update can vary. Without taking the time between calls into account, the game would seem to speed up and slow down. The time elapsed between calls to the Update method is available in the Update method's gameTime parameter. You can reset the elapsed times by calling ResetElapsedTime.

When using a variable-step game loop, you should express rates—such as the distance a sprite moves—in game units per millisecond (ms). The amount a sprite moves in any given update can then be calculated as the rate of the sprite times the elapsed time. Using this approach to calculate the distance the sprite moved ensures that the sprite will move consistently if the speed of the game or computer varies.

Motion Animation 遊戲角色的位置隨時間而變。 玩家控制角色移動 自主性移動:遊戲角色按照既定路徑而移動, 不受外界因素的干擾(碰撞除外)。 被動性移動:遊戲角色的移動受到其他角色的 牽引,如追逐與逃脫。 如何設定移動路徑?

移動路徑 直線路徑 速率 (velocity) = 單位時間的位移向量 (dx, dy) 速度 (speed) = 單位時間的位移長度 = | (dx, dy) | 距離 (distance) = 速度  時間

多線段路徑 計算簡單 足夠密的多線段可以用來模擬曲線路徑

曲線路徑 explicit formula: 簡單曲線如二次錐線 parametric formula: 複雜曲線或 Bezier curves 足夠密的多線段

範例一:顯示棒球圖片 public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D baseball; Vector2 baseball_position;

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 baseball = Content.Load ("images/baseball"); baseball_position = new Vector2(0, (GraphicsDevice.Viewport.Height - baseball.Height) / 2); }

protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(baseball, baseball_position, Color.White); spriteBatch.End(); base.Draw(gameTime); }

範例二:讓棒球水平飛 public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D baseball; Vector2 baseball_position, baseball_velocity;

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 baseball = Content.Load ("images/baseball"); baseball_position = new Vector2(0, (GraphicsDevice.Viewport.Height - baseball.Height) / 2); baseball_velocity = new Vector2(5,0); }

protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here // update baseball position baseball_position += baseball_velocity; base.Update(gameTime); }

範例三:不讓棒球飛出界外 W w W - w

public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D baseball; Vector2 baseball_position, baseball_velocity; int maxRight;

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 baseball = Content.Load ("images/baseball"); baseball_position = new Vector2(0, (GraphicsDevice.Viewport.Height - baseball.Height) / 2); baseball_velocity = new Vector2(5,0); maxRight = GraphicsDevice.Viewport.Width – baseball.Width; }

protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here // update baseball position baseball_position += baseball_velocity; if (baseball_position.X > maxRight) baseball_position.X = maxRight; base.Update(gameTime); }

範例四:讓棒球反彈 (a, 0) (-a, 0) (a, 0) (-a, 0)

protected override void Update(GameTime gameTime) {... // TODO: Add your update logic here // update baseball position baseball_position += baseball_velocity; if (baseball_position.X > maxRight) { baseball_position.X = maxRight; baseball_velocity = -baseball_velocity; } else if (baseball_position.X < 0) { baseball_position.X = 0; baseball_velocity = -baseball_velocity; } base.Update(gameTime); }

Game Components 模組化元件 GameComponent DrawableGameComponents Game.Components GameServiceContainer Game.Services

使用 Game Component 的步驟 1. 利用 IDE 的專案新增項目功能加入 Game Component 骨架碼。 2. 如果元件不牽涉繪圖,則建立一個繼承 GameComponent 的類別, 並依需求改寫其中的 Initialize 與 Update 的方法。 3. 如果元件牽涉繪圖,則建立一個繼承 DrawableGameComponent 的 類別,並依需求改寫其中的 Initialize 、 Update 、與 Draw 的方法。 4. 在 Game1 的建構函式中,用 Components.Add 方法把上述類別的 元件加入 Game1 物件的元件集中。

加入 Game Component 骨架碼 步驟一:在專案名稱上按滑鼠右鍵,然後如下圖所示,加入新增項目:

步驟二:選擇如下圖所示的項目。 123

Game Services Game services are a mechanism for maintaining loose coupling between objects that need to interact with each other. Game Services Provider Comsumer AddService GetService public void AddService ( Type type, Object provider ) public Object GetService (Type type)

範例五:利用 game components 來加入動畫元件 (DrawableComponent.rar) // File: BallComponent.cs public class BallComponent : Microsoft.Xna.Framework.DrawableGameComponent { protected Texture2D sprite;// sprite 的圖片 protected SpriteBatch spriteBatch;// 用於繪製 sprite protected Vector2 position;// sprite 的位置 protected Vector2 velocity;// sprite 的速率 protected string contentPath;// 圖片的路徑

public BallComponent(Game game, string path) : base(game) { // TODO: Construct any child components here contentPath = path; } protected override void LoadContent() { spriteBatch = Game.Services.GetService(typeof(SpriteBatch)); sprite = Game.Content.Load (contentPath); base.LoadContent(); } File: BallComponent.cs

public override void Draw (GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(sprite, position, Color.White); spriteBatch.End(); base.Draw(gameTime); } File: BallComponent.cs

public class BaseBall : BallComponent { int maxRight; public BaseBall(Game game, string path) : base(game, path) { // TODO: Construct any child components here } File: BaseBall.cs

protected override void LoadContent() { base.LoadContent(); position = new Vector2(0, (GraphicsDevice.Viewport.Height - sprite.Height)/2); velocity = new Vector2(3, 0); maxRight = GraphicsDevice.Viewport.Width - sprite.Width; } File: BaseBall.cs

public override void Update(GameTime gameTime) { // TODO: Add your update code here position += velocity; if (position.X > maxRight) { position.X = maxRight; velocity.X = -velocity.X; } else if (position.X < 0) { position.X = 0; velocity.X = -velocity.X; } base.Update(gameTime); } File: BaseBall.cs

public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; Components.Add(new BaseBall(this, "images/baseball")); Components.Add(new BasketBall(this, "images/basketball")); } File: Game1.cs 建立 Baseball 物件與 BasketBall 物件 並加入遊戲物件成為其元件

protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } File: Game1.cs 執行遊戲元件集( Components )中各元件 的 Initialize() 方法(其中也執行該元 件的 LoadContent() 方法)。

protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(typeof(SpriteBatch), spriteBatch); …… } File: Game1.cs 把 spriteBatch 加入 Services

protected override void Update(GameTime gameTime) {... // TODO: Add your update logic here base.Update(gameTime); } File: Game1.cs 執行遊戲元件集( Components )中各元件 的 Update() 方法。

protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here base.Draw(gameTime); } File: Game1.cs 執行遊戲元件集( Components )中各個可 繪元件的 Draw() 方法。

Sprite Animation Sprite Sheet Play List Frame Rate & Animation Speed

Sprite Sheet 為了減少圖片的數量,我 們通常把用來組合動作的 sprites 擺在一張圖片中, 稱之為 sprite sheet 。譬 如,右圖是一個轉動三環 動畫套圖的組合。

Sprite 指定法 – 2D 若把 sprite sheet 中的 sprite 安排如右圖所示 的 2D array 結構。 第 (i, j) 的 sprite 所佔據的 矩形區域的左上角座標 為 (i  w, j  h) (0,0)(1,0)(2,0)(3,0)(4,0)0 (0,1)(1,1)(2,1)(3,1)(4,1)1 (0,2)(1,2)(2,2)(3,2)(4,2)2 (0,3)(1,3)(2,3)(3,3)(4,3)3 (0,4)(1,4)(2,4)(3,4)(4,4)4 (0,5)(1,5)(2,5)(3,5)(4,5) h w

Sprite 指定法 – 1D 若把 sprite sheet 中的 sprite 安排如右圖所示的 2D array 結構。 假定 sprite sheet 含有 m  n (行  列) 個 sprites ,則第 k 個 sprite 所佔據的矩形區域的 左上角座標為 (k % m  w, k / m  h) h w 整數除法

Play List Sprite sheet 通常含多個動作組合(如下圖所示)。 Play list 記錄某一動作的所需的 sprite 及其順序。 譬如:出右拳的動作 序列為 0 , 10 , 12, 11, 12,

Frame Rate & Animation Speed Frame Rate: 遊戲迴圈的更新率(預設為 60 fps ) Animation Speed: sprite 動畫的播放速度,由動畫設計師 來決定。

範例: Sprite Animation (AnimatedSprites.rar) public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; // Texture stuff Texture2D texture; Point frameSize = new Point(75, 75); // (width, height) Point currentFrame = new Point(0, 0); // (i, j) Point sheetSize = new Point(6, 8); // (col, row) // Framerate stuff int timeSinceLastFrame = 0; int millisecondsPerFrame = 50;

protected override void Update(GameTime gameTime) {... timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastFrame > millisecondsPerFrame) { timeSinceLastFrame -= millisecondsPerFrame; ++currentFrame.X; if (currentFrame.X >= sheetSize.X) { currentFrame.X = 0; ++currentFrame.Y; if (currentFrame.Y >= sheetSize.Y) currentFrame.Y = 0; } base.Update(gameTime); }

protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.White); spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); spriteBatch.Draw(texture, Vector2.Zero, new Rectangle(currentFrame.X * frameSize.X, currentFrame.Y * frameSize.Y, frameSize.X, frameSize.Y), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0); spriteBatch.End(); base.Draw(gameTime); }