Index out of range?

Unten sind zwei 2D-Objekte, Array-und Vector. Wie Sie sehen können die beschriebenen Informationen in beiden ist identisch. Mein Spiel funktioniert einwandfrei mit dem Array-Objekt, aber mit Vektor ist, wirft die folgende Fehlermeldung:

[Fault] exception, information=RangeError: Error #1125: The index 10 is out of range 10. 

var _platformMap:Array = [
       [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
       [00, 00, 10, 10, 10, 10, 10, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 00, 00, 00, 10],
       [10, 10, 10, 00, 00, 10, 10, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
       [10, 10, 00, 00, 00, 00, 00, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
       [00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
     ];

var _platformMap:Vector.<Vector.<int>> = Vector.<Vector.<int>>(
        [
            Vector.<int>([10,10,10,10,10,10,10,10,10,10]), 
            Vector.<int>([00,00,10,10,10,10,10,10,10,10]), 
            Vector.<int>([10,10,10,10,01,01,01,10,10,10]), 
            Vector.<int>([10,10,10,00,10,10,10,10,01,10]), 
            Vector.<int>([10,10,10,00,10,10,01,01,01,00]), 
            Vector.<int>([10,10,10,10,01,01,01,01,01,10]), 
            Vector.<int>([00,00,00,00,00,10,10,10,10,10]), 
            Vector.<int>([00,00,00,00,00,00,00,00,00,00])
        ]
    );

Habe ich gelesen, dass die Vector-Objekte über die Laufzeit-Bereichsüberprüfung (oder festlängenüberprüfung) neben Arrays. Könnte dies das problem sein?

public class TileCollisionController
{
    private var _softPlatformOpen:Boolean = true;
    private var _elevatorOpen:Boolean = true;

    public function TileCollisionController()
    {}

    public function platformCollision(gameObject:TileModel, platformMap:Vector.<Vector.<int>>, maxTileSize:uint, platform:uint):void
    {
        var overlapX:Number;
        var overlapY:Number;
        //check top-left corner
        if (platformMap[gameObject.top][gameObject.left] == platform)
        {
            overlapX = gameObject.xPos % maxTileSize;
            overlapY = gameObject.yPos % maxTileSize;
            if (overlapY >= overlapX)
            {
                if (gameObject.vy < 0 && platformMap[gameObject.bottom][gameObject.left] != platform)
                {
                    //Collision on top side of the object
                    gameObject.setY = gameObject.mapRow * maxTileSize;
                    gameObject.vy = 0;
                }
            }
            else
            {
                //Collision on left side of the object
                gameObject.setX = gameObject.mapColumn * maxTileSize;
                gameObject.vx = 0;
            }
        }
        //check top-right corner
        if (platformMap[gameObject.top][gameObject.right] == platform)
        {
            overlapX = maxTileSize - ((gameObject.xPos + gameObject.width) % maxTileSize);
            overlapY = gameObject.yPos % maxTileSize;
            if (overlapY >= overlapX)
            {
                if (gameObject.vy < 0 && platformMap[gameObject.bottom][gameObject.right] != platform)
                {
                    gameObject.setY = (gameObject.mapRow * maxTileSize);
                    gameObject.vy = 0;
                }
            }
            else
            {
                //Collision on right
                gameObject.setX = (gameObject.mapColumn * maxTileSize) + ((maxTileSize - gameObject.width) - 1);
                gameObject.vx = 0;
            }
        }
        //check bottom-left corner
        if (platformMap[gameObject.bottom][gameObject.left] == platform)
        {
            overlapX = gameObject.xPos % maxTileSize;
            overlapY = maxTileSize - ((gameObject.yPos + gameObject.height) % maxTileSize);
            if (overlapY >= overlapX)
            {
                if (gameObject.vy > 0 && platformMap[gameObject.top][gameObject.left] != platform)
                {
                    //trace("Collision on bottom");
                    //Collision on bottom
                    gameObject.setY = (gameObject.mapRow * maxTileSize) + (maxTileSize - gameObject.height);
                    gameObject.vy = 0;
                    gameObject.jumping = false;
                }
            }
            else
            {
                //trace("Collision on bottom left");
                //Collision on left
                gameObject.setX = gameObject.mapColumn * maxTileSize;
                gameObject.vx = 0;
            }
        }
        //check bottom-right corner
        if (platformMap[gameObject.bottom][gameObject.right] == platform)
        {
            overlapX = maxTileSize - ((gameObject.xPos + gameObject.width) % maxTileSize);
            overlapY = maxTileSize - ((gameObject.yPos + gameObject.height) % maxTileSize);
            if (overlapY >= overlapX)
            {
                if (gameObject.vy > 0 && platformMap[gameObject.top][gameObject.right] != platform)
                {
                    //trace("Collision on bottom right");
                    //Collision on bottom
                    gameObject.setY = (gameObject.mapRow * maxTileSize) + (maxTileSize - gameObject.height);
                    gameObject.vy = 0;
                    gameObject.jumping = false;
                }
            }
            else
            {
                //trace("Collision on right");
                //Collision on right
                gameObject.setX = (gameObject.mapColumn * maxTileSize) + ((maxTileSize - gameObject.width) - 1);
                gameObject.vx = 0;
            }
        }
    }

}

}

Siehe Beispiel

    public function platformCollision(gameObject:TileModel, platformMap:Vector.<Vector.<int>>, maxTileSize:uint, platform:uint):void
    {
        var overlapX:Number;
        var overlapY:Number;
        if(gameObject.bottom < platformMap.length && gameObject.right < platformMap[0].length)
        {
        //check top-left corner
        //...


Beispiel nach updates

InformationsquelleAutor LuciM | 2013-01-10
Schreibe einen Kommentar