loading graphic layers works with right order

This commit is contained in:
Jeena 2014-11-15 17:02:27 +01:00
parent 522b5092f5
commit 9c9db8ca8c
6 changed files with 132 additions and 33 deletions

View file

@ -88,6 +88,13 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
return paths;
};
Level.prototype.setupLayer = function(options, behind, referenceId) {
Parent.prototype.setupLayer.call(this, options, behind, referenceId);
console.log(options.layerId, behind, referenceId);
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, behind, referenceId);
};
/*
Level.prototype.createItems = function(options) {
options.layerId = AbstractLayer.ID.ITEM;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
@ -110,5 +117,10 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
Parent.prototype.createSpawnPoints.call(this, options);
};
Level.prototype.createContainer = function(options) {
Parent.prototype.createContainer.call(this, options);
};
*/
return Level;
});

View file

@ -1,9 +1,10 @@
define([
"Game/Core/Loader/TiledLevel",
"Game/Config/Settings"
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
],
function (Parent, Settings) {
function (Parent, Settings, Nc) {
function TiledLevel(uid, engine, gameObjects) {
this.layerId = "background";
@ -55,12 +56,38 @@ function (Parent, Settings) {
paths.push(texturePath);
};
// FIXME: iterate through image layers and add images
var background = this.getLayer(levelData, "background");
paths.push(Settings.MAPS_PATH + background.image);
return paths;
}
TiledLevel.prototype.setupLayer = function(options, behind, referenceId) {
Parent.prototype.setupLayer.call(this, options, behind, referenceId);
// So far only one image per layer is possible because of Tiled editor
if (options.type == "imagelayer") {
var texturePath = Settings.MAPS_PATH + options.image;
var callback = function(mesh) {
Nc.trigger(Nc.ns.client.view.mesh.add, options.layerId, mesh);
}
Nc.trigger(Nc.ns.client.view.mesh.create,
options.layerId,
texturePath,
callback,
{
x: 200
}
);
}
};
TiledLevel.prototype.addBackground = function(options) {
var texturePath = Settings.GRAPHICS_PATH + options.image;

View file

@ -33,7 +33,6 @@ function (Abstract, DomController, Settings, Exception, Nc) {
}
Abstract.prototype.addMethod.call(AbstractView, 'render');
Abstract.prototype.addMethod.call(AbstractView, 'createAndInsert', ['id', 'parallaxSpeed', 'referenceId', 'behind']);
Abstract.prototype.addMethod.call(AbstractView, 'addFilter', ['mesh', 'options']);
Abstract.prototype.addMethod.call(AbstractView, 'removeFilter', ['mesh', 'options']);
Abstract.prototype.addMethod.call(AbstractView, 'setCameraPosition', ['x', 'y']);

View file

@ -22,7 +22,11 @@ function (Nc, Exception, Layer) {
];
}
LayerManager.prototype.createAndInsert = function(id, parallaxSpeed, referenceId, behind) {
/*
* If no referenceId is given, the layer is inserted in the far background (behind=true)
* or in the foreground (behind=false/null)
*/
LayerManager.prototype.createAndInsert = function(id, parallaxSpeed, behind, referenceId) {
var referenceIndex = -1;
behind = !!behind;
@ -44,11 +48,13 @@ function (Nc, Exception, Layer) {
}
var layer = new Layer(id, parallaxSpeed);
var layerIndex = behind ? referenceIndex -1 : referenceIndex;
var layerIndex = behind ? referenceIndex : referenceIndex + 1;
this.layers.splice(layerIndex, 0, layer);
this.rearrangeLayers();
console.log(this.layers.map(function(o) {return o.name}))
};
LayerManager.prototype.rearrangeLayers = function() {