Hello -
I have recently begun development of a simple tile map engine, and I am having some trouble with my rendering. I have been trying to make the array extremely large in order to test it’s drawing capabilities, and it is way slower than I think it should be. It took over 10 minutes just to load a 75x250 grid (which is large, but I doubt it should take as long as it did)
My implementation is:
var map:Array<Array<Int>> = [
for (x in 0...250) [
for(y in 0...75)
1
]
];
for (i in 0...map.length) {
for(j in 0...map[0].length) {
var tile = new Tile(map[j][i]);
var x = i;
var y = j;
tile.setLoc(x, y);
addChild(tile);
}
}
and my Tile class is relatively simple:
class Tile extends Sprite {
private var image:Bitmap;
public function new(id:Int) {
super();
switch(id) {
case 1:
image = new Bitmap(Assets.getBitmapData("assets/GrassLeft.png"));
case 2:
image = new Bitmap(Assets.getBitmapData("assets/GrassRight.png"));
case 3:
image = new Bitmap(Assets.getBitmapData("assets/GrassCenter.png"));
}
if(image != null) addChild(image);
}
public function setLoc(x:Int, y:Int) {
if (image != null) {
image.x = x * Main.TILE_WIDTH;
image.y = y * Main.TILE_HEIGHT;
}
}
}