以下は、Array と Vector の 2 つの 2D オブジェクトです。ご覧のとおり、両方に記載されている情報は同じです。私のゲームは Array オブジェクトを使用して問題なく動作しますが、Vector を使用すると次のエラーがスローされます。
[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])
]
);
Vector オブジェクトには、配列以外に実行時の範囲チェック (または固定長チェック) があることを読みました。これが問題でしょうか?
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;
}
}
}
}
例
を見る
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
//...