Note that there are some explanatory texts on larger screens.

plurals
  1. POIndex out of range?
    primarykey
    data
    text
    <p>Below are two 2D objects, Array and Vector. As you can see the information described in both is identically. My game works flawlessly using the Array object, but with Vector is throws the following error:</p> <pre><code>[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.&lt;Vector.&lt;int&gt;&gt; = Vector.&lt;Vector.&lt;int&gt;&gt;( [ Vector.&lt;int&gt;([10,10,10,10,10,10,10,10,10,10]), Vector.&lt;int&gt;([00,00,10,10,10,10,10,10,10,10]), Vector.&lt;int&gt;([10,10,10,10,01,01,01,10,10,10]), Vector.&lt;int&gt;([10,10,10,00,10,10,10,10,01,10]), Vector.&lt;int&gt;([10,10,10,00,10,10,01,01,01,00]), Vector.&lt;int&gt;([10,10,10,10,01,01,01,01,01,10]), Vector.&lt;int&gt;([00,00,00,00,00,10,10,10,10,10]), Vector.&lt;int&gt;([00,00,00,00,00,00,00,00,00,00]) ] ); </code></pre> <p>I read about that Vector objects have runtime range checking (or fixed-length checking) besides Arrays. Could this be the problem?</p> <pre><code>public class TileCollisionController { private var _softPlatformOpen:Boolean = true; private var _elevatorOpen:Boolean = true; public function TileCollisionController() {} public function platformCollision(gameObject:TileModel, platformMap:Vector.&lt;Vector.&lt;int&gt;&gt;, 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 &gt;= overlapX) { if (gameObject.vy &lt; 0 &amp;&amp; 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 &gt;= overlapX) { if (gameObject.vy &lt; 0 &amp;&amp; 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 &gt;= overlapX) { if (gameObject.vy &gt; 0 &amp;&amp; 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 &gt;= overlapX) { if (gameObject.vy &gt; 0 &amp;&amp; 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; } } } } </code></pre> <p>}<br> <a href="http://imageshack.us/photo/my-images/402/picbi.jpg/" rel="nofollow">See example</a> <br></p> <pre><code> public function platformCollision(gameObject:TileModel, platformMap:Vector.&lt;Vector.&lt;int&gt;&gt;, maxTileSize:uint, platform:uint):void { var overlapX:Number; var overlapY:Number; if(gameObject.bottom &lt; platformMap.length &amp;&amp; gameObject.right &lt; platformMap[0].length) { //check top-left corner //... </code></pre> <p><br> <a href="http://imageshack.us/photo/my-images/248/pic2cu.jpg/" rel="nofollow">Example after updates</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload