added layers

This commit is contained in:
Jeena 2014-07-27 17:21:37 +02:00
parent 7c783d19e8
commit d29c64385d
4 changed files with 142 additions and 108 deletions

View file

@ -10,7 +10,21 @@ function (Parent, Settings) {
}
TiledLevel.prototype = Object.create(Parent.prototype);
TiledLevel.prototype.setup = function(levelData) {
/*
FIXME: find a name for this shit!
for (var i = 0; i < levelData.layers.length; i++) {
var layerOptions = levelData.layers[i];
layerOptions.z = i;
if(!this.layerMapping[layerOptions.name]) {
this.createLayer(layerOptions);
}
};
*/
Parent.prototype.setup.call(this, levelData);
};
TiledLevel.prototype.getAssetPaths = function(levelData) {
var paths = Parent.prototype.getAssetPaths.call(this, levelData);
@ -44,9 +58,32 @@ function (Parent, Settings) {
paths.push(Settings.MAPS_PATH + background.image);
return paths;
}
TiledLevel.prototype.addBackground = function(options) {
var texturePath = Settings.GRAPHICS_PATH + options.image;
var callback = function (mesh) {
Nc.trigger(Nc.ns.client.view.mesh.add, mesh, 0); // FIXME: add at z layer -1 or so
}
Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, {
width: 4000,
height: 2959,
x: -(4000 - Settings.STAGE_WIDTH) / 2,
y: -(2959 + Settings.STAGE_HEIGHT + 700) / 2
});
}
TiledLevel.prototype.getLayer = function(levelData, name) {
for (var i = 0; i < levelData.layers.length; i++) {
if(levelData.layers[i].name === name) {
return levelData.layers[i];
}
}
throw "Layer '" + name + "' not found.";
};
return TiledLevel;
});