I am trying to get data from json file to render tilemap. But I am getting this error all the time Uncaught ReferenceError: renderTileMap is not defined
.
I tried to place body of renderTileMap function into $.getJSON function and it works. Map is rendered in 0.2 ms so no long waiting. JSON file is also correct. I have no idea why javascript cannot see this method.
getData() {
$.getJSON(this.file, renderTileMap);
}
renderTileMap(json) {
var actPosX = this.beginPosX;
var actPosY = this.beginPosY;
var activeTile = 0;
var tiles = json.tiles;
var tilesResources = json.tilesResources;
var lines = tiles.length / this.lineSize;
var i, y;
for(i = 1; i < lines; i++) {
for(y = 1; y < this.lineSize; y++) {
ctx.fillStyle = tilesResources[tiles[activeTile]];
ctx.fillRect(actPosX,actPosY, this.tileWidth, this.tileHeight);
actPosX += this.tileWidth;
activeTile++;
}
actPosY += this.tileHeight;
actPosX = this.beginPosX;
}
}