Reputation: 173
I'm designing a chess game in ActionScript 3 using Flash Professional CC. I've created a chessboard using the IDE and placed pieces in their initial positions. Each tile has its own instance and is named its respective coordinate e.g. the top left tile is called A8.
For calculating moves that are valid and such, I planned to use two 2D arrays of objects. One array should contain the tile instances e.g. A8, B8, C8, D8 etc. and the other should contain the pieces of the board e.g. BR1, BB1.
I've noticed that ActionScript does not allow one to implement 2D arrays like C++ (a language I'm familiar with); instead, nested arrays are used. I'm slightly confused about how to set up these arrays. What is the most efficient way to declare and initialise these arrays (hopefully not involving repetitive code)?
Upvotes: 2
Views: 633
Reputation: 3141
welcome to the army of AS3 developers.
Here's few tips for you:
var array:Array = [];
and here's a 2d Array - var a:Array = [[]];
. Arrays are dynamic object, you don't need to specify the depth of the array. So when adding tile to the array just add them via array[x][y] = tile
var myVector:Vector.< Tile > = new Vector.< Tile >();
and 2d version var myVector:Vector< Vector.< Tile > >;
and so on.Vectors are faster than Arrays.
More tips:
Upvotes: 1