我有以下問題:我有這個多級數組(嵌套數組),其中包含兩行bitmapData。第1行:360位旋轉的bitmapData對象;第2行:360旋轉和彩色的bitmapData對象。嵌套數組不工作
我嘗試訪問第2行,但不起作用。有一些神祕的錯誤消息(「TypeError:Error#1034:Type Coercion failed:can not [] @ 36d7e9e9 to flash.display.BitmapData。at BasicBlitArrayObject/updateFrame()」)。
請問有人可以幫我解決這個問題嗎?非常感謝你。
此函數旋轉並着色bitmapData;旋轉後的bitmapData被拋入一個數組中,彩色的bitmapData被拋入另一個數組中;第三陣列用作級陣列中嵌套它
public function createColoredRotationBlitArrayFromBD(sourceBitmapData:BitmapData, inc:int, offset:int = 0, color:Number = 1, $alpha:Number = 1):Array
{
tileList = [];
tileListSec = [];
levelArray = [tileList, tileListSec];
var rotation:int = offset;
while (rotation < (360 + offset))
{
var angleInRadians:Number = Math.PI * 2 * (rotation/360);
var rotationMatrix:Matrix = new Matrix();
rotationMatrix.translate(-sourceBitmapData.width * .5, -sourceBitmapData.height * .5);
rotationMatrix.rotate(angleInRadians);
rotationMatrix.translate(sourceBitmapData.width * .5, sourceBitmapData.height * .5);
var matrixImage:BitmapData = new BitmapData(sourceBitmapData.width, sourceBitmapData.height,
true, 0x00000000);
matrixImage.draw(sourceBitmapData, rotationMatrix);
tileList.push(matrixImage.clone());
bitmapData = new BitmapData(matrixImage.width, matrixImage.height, true, 0x00000000);
bitmapData = matrixImage;
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter (
[color, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, $alpha, 0]);
matrixImage.applyFilter(bitmapData, bitmapData.rect, point0, colorMatrix);
tileListSec.push(matrixImage.clone());
rotation += inc;
matrixImage.dispose();
matrixImage = null;
rotationMatrix = null;
bitmapData.dispose();
bitmapData = null;
colorMatrix = null;
}
return(levelArray);
}
創建我的旋轉和有色位圖數據
animationFrames = tempBlitArrayAsset.createRotationBlitArrayFromBD($bitmapData, 1, 270);
這裏的其他兩個數組我嘗試訪問我的水平陣列的第一行(即不工作;我不能訪問它)
tempEnemy.animationList = animationFrames;
tempEnemy.bitmapData = tempEnemy.animationList[1][tempEnemy.frame];
該功能是用於更新幀
public function updateFrame(inc:int, row:int = 0):void
{
frame += inc;
if (frame > animationList.length - 1){
frame = 0;
}
bitmapData = animationList[row][frame];
}
}
這是顯示updateFrame功能是如何在我的遊戲中使用的線路(trueRotation爲0)
tempEnemy.updateFrame(tempEnemy.trueRotation);
它看起來像一個數組越來越推到你期望的位圖數據。您是否嘗試過使用強類型向量而不是數組。如果你知道它總是會有bitmapdatas,那麼它是有道理的,當你在那裏放置一些沒有意義的東西時它會拋出一個運行時異常。我會在後面更詳細地看代碼,看看我是否能夠確切地知道它發生在哪裏 –
不,我還沒有嘗試過一個向量。我個人認爲這不是問題。儘管如此,我會稍後再嘗試... – drpelz