I’m having trouble hooking up the Tilemap and getting it to display. It compiles fine, but I get WebGL errors showing no texture is bound to the target, and I’ve gone through my code and refactored a dozen or so times to no avail.
Game.hx
this.map = TileMapService.instance
.setDimensions(10,15)
.setTileSize(32)
.setTilesetFromFile("assets/underground.png")
.setContainer(container)
.createWorld();
TileMapService.hx
public function setDimensions(width:UInt, height:UInt):TileMapService {
this.width = width;
this.height = height;
return this;
}
public function setTileSize(size:UInt):TileMapService {
this.tileSize = size;
return this;
}
public function setTilesetFromFile(filePath:String):TileMapService {
var bitmapData = BitmapData.fromFile(filePath);
this.tileset = new Tileset(bitmapData);
this.enumMap.set(TileType.EMPTY, this.tileset.addRect(new Rectangle(0,0,32,32)));
this.enumMap.set(TileType.WALL, this.tileset.addRect(new Rectangle(32,0,32,32)));
return this;
}
public function setContainer(container:DisplayObjectContainer):TileMapService {
this.container = container;
this.tilemap = new Tilemap(container.stage.stageWidth, container.stage.stageHeight, this.tileset);
container.addChild(this.tilemap);
return this;
}
public function createWorld():TileMapService {
var size = this.width * this.height;
var tileArray = new TileArray(size);
for (i in 0...size) {
var x = (i % this.width);
var y = Util.fint(i / this.width);
tileArray.position = i;
tileArray.matrix = new Matrix(1,0,0,1,x,y);
}
tilemap.setTiles (tileArray);
return this;
}
enum TileType {
EMPTY;
WALL;
}
I did originally set the tilemap directly rather than assigning it with the tilearray, but that caused the same error and I like this more direct method better. No part of the tilemap appears on-screen. Any help would be greatly appreciated.
If I change the path assets/underground.png
it will complain about not being able to find it, and I can confirm that in the browser it serves to the correct path that it is looking for.