开发者

nested array does not work

I have the following problem: I have this multi-level array (nested array) which contains two rows of bitmapData. Row 1:360 rotated bitmapData objects; row 2: 360 rotated and colored bitmapData objects.

I try to access row 2 but that doesn't work. There are some mysterious error messages coming up ("TypeError: Error #1034: Type Coercion failed: cannot convert []@36d7e9e9 to flash.display.BitmapData. at BasicBlitArrayObject/updateFrame()").

Please can someone help me out with this problem? Thank you very much.

this function rotates and colors bitmapData; the rotated bitmapData is thrown into an array and the colored bitmapData is thrown into another array; a third array is used as a level array for nesting the other two arrays inside of it

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(source开发者_JS百科BitmapData.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);

}

creating my rotated and colored bitmapData

animationFrames = tempBlitArrayAsset.createRotationBlitArrayFromBD($bitmapData, 1, 270);

here I try to access the first row of my level array (that doesn't work; I can't access it)

tempEnemy.animationList = animationFrames;
tempEnemy.bitmapData = tempEnemy.animationList[1][tempEnemy.frame];

This function is for updating the frames

public function updateFrame(inc:int, row:int = 0):void
{
frame += inc;

if (frame > animationList.length - 1){
    frame = 0;
}
bitmapData = animationList[row][frame];                 


}

}   

this is a line showing how the updateFrame-function is used in my game (trueRotation is 0)

tempEnemy.updateFrame(tempEnemy.trueRotation);


I can't find anything wrong with createColoredRotationBlitArrayFromBD

var $bitmapData:BitmapData = new BitmapData(40,40,false, 0x7f7f7f);
var animationFrames:Array = createColoredRotationBlitArrayFromBD($bitmapData, 1, 270);
trace(animationFrames.length);   // 2
trace(animationFrames[0].length);  // 360
trace(animationFrames[1].length);  // 360

var bitmap:Bitmap = new Bitmap();
this.addChild(bitmap);
bitmap.bitmapData = animationFrames[1][0]; // works..

That seems correct. Right? I get a red tinted bitmap.

The only 'bug' I see in the code you listed is in updateFrame

if (frame > animationList.length - 1){
    frame = 0;
}

should probably be:

if (frame > animationList[row].length - 1){
    frame = 0;
}

because animationList.length == 2

But everything else looks okay in the code you've provided, so without more code, i'm not sure there is anything to help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜