我們想要讓這一系列的圖片輪流播放,就像在卡通裡看到的那樣讓角色動起來
![]() |
截至http://www.coronalabs.com/ |
首先因為一張圖中共有八個動作,所以要將這張圖分為八張小圖
然後使用imageSheet API 將圖放入imageSheet當作圖片來源
使用imageSheet能夠加快讀寫的速度,也能減少記憶體的消耗
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local options = | |
{ | |
-- The params below are required | |
width = 512, --切成每張圖的寬為512pixel | |
height = 256, --切成每張圖的高為256pixel | |
numFrames = 8, | |
-- The params below are optional; used for dynamic resolution support | |
sheetContentWidth = 1024, -- width of original 1x size of entire sheet | |
sheetContentHeight = 1024 -- height of original 1x size of entire sheet | |
} | |
local imageSheet = graphics.newImageSheet( "runningcat-full.png", options ) |
要讓這八張小圖依順序播放,以產生在跑動的視覺效果
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local sequenceData = | |
{ | |
name="walking", --給予命名,之後可用animation:Setsequence("walking")來做切換 | |
start=1, --從1播到8,可做變動增加了解 | |
count=8, | |
time=400, -- 每0.4秒換一張圖片 | |
loopCount = 0, -- Optional. Default is 0 (loop indefinitely) | |
} | |
-- 使用動畫精靈newSprite | |
local animation = display.newSprite( imageSheet, sequenceData ) | |
animation:play() --開始播放動畫 | |
--animation:setFrame( frame ) --用來指定播放第幾格 | |
--animation:pause() --用來暫停播放 |
很簡單吧!
來自小島
沒有留言:
張貼留言