As you figured in the comment on John's answer, there is no built-in for 2d arrays that I know of, but it's not hard to create one.
Here I've made 2 helper functions, one uses haxe.ds.Vector
, which is new in Haxe 3 and is optimised for fixed size collections. The other uses normal arrays, so may be slower on some platforms, and technically isn't fixed width, just initialised to a certain size.
import haxe.ds.Vector;
class Vector2DTest
{
static function main()
{
// 2D vector, fixed size, sometimes faster
var v2d = Vector2D.create(3,5);
v2d[0][0] = "Top Left";
v2d[2][4] = "Bottom Right";
trace (v2d);
// [[Top Left,null,null,null,null],[null,null,null,null,null],[null,null,null,null,Bottom Right]]
// 2D array, technically variable size, but you'll have to initialise them. Sometimes slower.
var a2d = Array2D.create(3,5);
a2d[0][0] = "Top Left";
a2d[2][4] = "Bottom Right";
trace (a2d);
// [[Top Left,null,null,null,null],[null,null,null,null,null],[null,null,null,null,Bottom Right]]
}
}
class Vector2D
{
public static function create(w:Int, h:Int)
{
var v = new Vector(w);
for (i in 0...w)
{
v[i] = new Vector(h);
}
return v;
}
}
class Array2D
{
public static function create(w:Int, h:Int)
{
var a = [];
for (x in 0...w)
{
a[x] = [];
for (y in 0...h)
{
a[x][y] = null;
}
}
return a;
}
}
The Vector2D will only work on Haxe 3 (released later this month), Array2D should work fine on Haxe 2 also.