Skip to content

Instantly share code, notes, and snippets.

@caubry
Last active January 3, 2016 16:49
Show Gist options
  • Save caubry/8491466 to your computer and use it in GitHub Desktop.
Save caubry/8491466 to your computer and use it in GitHub Desktop.
var TILEDMapClass = Class.extend({
currMapData: null,
numXTiles: 100,
numYTiles: 100,
tileSize: {
"x": 64,
"y": 64
},
pixelSize: {
"x": 64,
"y": 64
},
imgLoadCount: 0,
fullyLoaded: false,
load: function (map) {
xhrGet(map, function (data) {
gMap.parseMapJSON(data.responseText);
});
},
parseMapJSON: function (mapJSON) {
var map = gMap.currMapData;
gMap.numXTiles = map.width;
gMap.numYTiles = map.height;
gMap.tileSize.x = map.tilewidth;
gMap.tileSize.y = map.tileheight;
gMap.pixelSize.x = gMap.numXTiles * gMap.tileSize.x;
gMap.pixelSize.y = gMap.numYTiles * gMap.tileSize.y;
for(var i = 0; i < map.tilesets.length; i++){
var img = new Image();
img.onload = gMap.onloaded(map.tilesets);
img.src = "../data/" + map.tilesets[i].image.replace(/^.*[\\\/])/, '');
}
},
onloaded: function(tile){
gMap.imgLoadCount++;
if (gMap.imgLoadCount === tile.length){
gMap.fullyLoaded = true;
}
}
});
var gMap = new TILEDMapClass();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment