0
我想緩存我spritesheet(tilesheet)到一個數組。我這樣做是因爲每個spritesheet須數組內被緩存,所以我對象可以從他們輕鬆地將他們的瓷磚。但我緩存似乎並沒有工作,因爲絕對沒有被呈現出來。我什麼也看不見。緩存和渲染spritesheets不起作用
我的緩存裏面有東西(可能是bitmapData),它不爲空,所以目前我不知道問題出在哪裏。
有人可以幫我解決這個問題嗎?
該功能應通過copypixels陣列的每個瓦片渲染背景
public function renderCachedTile(canvasBitmapData:BitmapData, tileArray:Array):void
{
tileCache = tileArray;
tileArray = [];
x = nextX;
y = nextY;
point.x = x;
point.y = y;
tileRect.x = tileWidth;
tileRect.y = tileHeight;
if (animationCount >= animationDelay)
{
animationCount = 0;
if(reverse)
{
currentTile--;
if (currentTile < 1)
{
currentTile = tilesLength - 1;
}
} else {
currentTile++;
if (currentTile >= tilesLength - 1)
{
currentTile = 0;
}
}
} else {
animationCount++;
}
canvasBitmapData.lock();
canvasBitmapData.copyPixels(tileCache[currentTile], tileRect, point);
canvasBitmapData.unlock();
}
這個功能我spritesheet「分離」到瓷磚和他們投擲到一個數組
private function tileToCache():void {
var tileBitmapData:BitmapData = new BitmapData(tileWidth, tileHeight, true, 0x00000000);
var tilePt:Point = new Point(0, 0);
var tileRect:Rectangle = new Rectangle;
tileCache = [];
for (var tileCtr:int = 0; tileCtr < tilesLength; tileCtr++) {
tileBitmapData.lock();
tileRect.x = int((tileCtr % spritesPerRow)) * tileWidth;
tileRect.y = int((tileCtr/spritesPerRow)) * tileHeight;
tileBitmapData.copyPixels(tileSheet, tileRect, tilePt);
tileBitmapData.unlock();
tileCache.push(tileBitmapData);
}
}
謝謝!我會嘗試這個儘快!希望這個作品... – drpelz