more layer work

This commit is contained in:
Jeena 2014-08-30 16:02:41 +02:00
parent b5c70687d8
commit 57135f3acc
7 changed files with 54 additions and 31 deletions

View file

@ -89,19 +89,22 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
}; };
Level.prototype.createItems = function(options) { Level.prototype.createItems = function(options) {
options.layer = AbstractLayer.ID.ITEM;
var layerName = AbstractLayer.ID.ITEM; Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layer, 1, AbstractLayer.ID.SPAWN, true);
Nc.trigger(Nc.ns.client.view.layer.createAndAdd, layerName);
options.layer = layerName;
Parent.prototype.createItems.call(this, options); Parent.prototype.createItems.call(this, options);
}; };
Level.prototype.createTiles = function(options) { Level.prototype.createTiles = function(options) {
options.layerId = AbstractLayer.ID.TILE;
var layerName = AbstractLayer.ID.TILE; Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
Nc.trigger(Nc.ns.client.view.layer.createAndAdd, layerName);
options.layer = layerName; Parent.prototype.createTiles.call(this, options);
};
Level.prototype.createSpawnPoints = function(options) {
options.layerId = AbstractLayer.ID.SPAWN;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1);
Parent.prototype.createTiles.call(this, options); Parent.prototype.createTiles.call(this, options);
}; };

View file

@ -14,8 +14,6 @@ function (Abstract, DomController, Settings, Exception, Nc) {
this.debugMode = false; this.debugMode = false;
this.ncTokens = [ this.ncTokens = [
Nc.on(Nc.ns.client.view.layer.createAndAdd, this.createAndAddLayer, this),
Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this), Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this),
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this), Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this),

View file

@ -1,11 +1,17 @@
define([ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception",
"Game/Client/View/Pixi/Layer"
], ],
function (Nc) { function (Nc, Exception, Layer) {
function LayerManager() { function LayerManager(stage) {
this.layers = [];
this.stage = stage;
this.ncTokens = [ this.ncTokens = [
Nc.on(Nc.ns.client.view.layer.createAndInsert, this.createAndInsert, this),
Nc.on(Nc.ns.client.view.mesh.create, this.createMesh, this), Nc.on(Nc.ns.client.view.mesh.create, this.createMesh, this),
Nc.on(Nc.ns.client.view.animatedMesh.create, this.createAnimatedMesh, this), Nc.on(Nc.ns.client.view.animatedMesh.create, this.createAnimatedMesh, this),
Nc.on(Nc.ns.client.view.mesh.add, this.addMesh, this), Nc.on(Nc.ns.client.view.mesh.add, this.addMesh, this),
@ -39,7 +45,7 @@ function (Nc) {
var layer = new Layer(id, parallaxSpeed); var layer = new Layer(id, parallaxSpeed);
var layerIndex = behind ? referenceIndex : referenceIndex + 1; var layerIndex = behind ? referenceIndex -1 : referenceIndex;
this.layers.splice(layerIndex, 0, layer); this.layers.splice(layerIndex, 0, layer);
this.stage.addChildAt(layer.getContainer(), layerIndex); this.stage.addChildAt(layer.getContainer(), layerIndex);
@ -57,37 +63,43 @@ function (Nc) {
LayerManager.prototype.delegate = function(methodName, layerId) { LayerManager.prototype.delegate = function(methodName, layerId) {
var layer = this.getLayerById(layerId); var layer = this.getLayerById(layerId);
var args = arguments.splice(0,2); var args = Array.prototype.splice.call(arguments, 0, 2);
layer[methodName].apply(layer, args); layer[methodName].apply(layer, args);
}; };
LayerManager.prototype.createMesh = function() { LayerManager.prototype.createMesh = function() {
this.delegate(arguments.splice(0,0,'createMesh')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createMesh'));
}; };
LayerManager.prototype.createAnimatedMesh = function() { LayerManager.prototype.createAnimatedMesh = function() {
this.delegate(arguments.splice(0,0,'createAnimatedMesh')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createAnimatedMesh'));
}; };
LayerManager.prototype.addMesh = function() { LayerManager.prototype.addMesh = function() {
this.delegate(arguments.splice(0,0,'addMesh')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addMesh'));
}; };
LayerManager.prototype.removeMesh = function() { LayerManager.prototype.removeMesh = function() {
this.delegate(arguments.splice(0,0,'removeMesh')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeMesh'));
}; };
LayerManager.prototype.updateMesh = function() { LayerManager.prototype.updateMesh = function() {
this.delegate(arguments.splice(0,0,'updateMesh')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'updateMesh'));
}; };
LayerManager.prototype.addFilter = function() { LayerManager.prototype.addFilter = function() {
this.delegate(arguments.splice(0,0,'addFilter')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addFilter'));
}; };
LayerManager.prototype.removeFilter = function() { LayerManager.prototype.removeFilter = function() {
this.delegate(arguments.splice(0,0,'removeFilter')); this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeFilter'));
};
LayerManager.prototype.destroy = function() {
for (var i = 0; i < this.ncTokens.length; i++) {
Nc.off(this.ncTokens[i]);
};
}; };
return LayerManager; return LayerManager;

View file

@ -13,15 +13,15 @@ function (Parent, PIXI) {
Layer.prototype = Object.create(Parent.prototype); Layer.prototype = Object.create(Parent.prototype);
Layer.prototype.getContainer = function() { Layer.prototype.getContainer = function() {
return this.contianer; return this.container;
}; };
Layer.prototype.show = function() { Layer.prototype.show = function() {
this.contianer.visible = true; this.container.visible = true;
}; };
Layer.prototype.hide = function() { Layer.prototype.hide = function() {
this.contianer.visible = false; this.container.visible = false;
}; };
Layer.prototype.addMesh = function(mesh) { Layer.prototype.addMesh = function(mesh) {

View file

@ -7,10 +7,10 @@ define([
"Lib/Utilities/NotificationCenter", "Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception", "Lib/Utilities/Exception",
"Game/Client/View/Pixi/GameStats", "Game/Client/View/Pixi/GameStats",
"Game/Client/View/Pixi/Layer" "Game/Client/View/LayerManager",
], ],
function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Exception, GameStats, Layer) { function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Exception, GameStats, LayerManager) {
var AVAILABLE_MESH_FILTERS = { var AVAILABLE_MESH_FILTERS = {
"blur": PIXI.BlurFilter, "blur": PIXI.BlurFilter,
@ -23,6 +23,7 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
Parent.call(this); Parent.call(this);
this.layerManager = null;
this.movableObjects = []; this.movableObjects = [];
this.stage = null; this.stage = null;
this.container = null; this.container = null;
@ -33,7 +34,6 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
this.init(); this.init();
this.pixi = PIXI; this.pixi = PIXI;
this.currentZoom = Settings.ZOOM_DEFAULT; this.currentZoom = Settings.ZOOM_DEFAULT;
this.layers = [];
PIXI.scaleModes.DEFAULT = PIXI.scaleModes.NEAREST; PIXI.scaleModes.DEFAULT = PIXI.scaleModes.NEAREST;
} }
@ -56,6 +56,8 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
this.stage = new PIXI.Stage(0x333333); this.stage = new PIXI.Stage(0x333333);
this.layerManager = new LayerManager(this.stage);
this.initCamera(); this.initCamera();
this.initLoader(); this.initLoader();
@ -283,6 +285,8 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
}; };
PixiView.prototype.destroy = function() { PixiView.prototype.destroy = function() {
this.layerManager.destroy();
for (var i = 0; i < this.stage.children.length; i++) { for (var i = 0; i < this.stage.children.length; i++) {
this.stage.removeChild(this.stage.children[i]); this.stage.removeChild(this.stage.children[i]);

View file

@ -31,8 +31,14 @@ define([
TiledLevel.prototype.setup = function(levelData) { TiledLevel.prototype.setup = function(levelData) {
this.levelData = levelData; this.levelData = levelData;
for (var i = 0; i < levelData.layers.length; i++) {
var layerOptions = levelData.layers[i]; // Make sure spawnpoints layer is created first
var layers = levelData.layers.sort(function(a, b) {
return a.name == "spawnpoints" ? -1 : b.name == "spawnpoints" ? 1 : 0;
});
for (var i = 0; i < layers.length; i++) {
var layerOptions = layers[i];
layerOptions.z = i; layerOptions.z = i;
if(this.layerMapping[layerOptions.name]) { if(this.layerMapping[layerOptions.name]) {

View file

@ -26,7 +26,7 @@ function (Exception) {
client: { client: {
view: { view: {
layer: { layer: {
createAndAdd: null createAndInsert: null
}, },
mesh: { mesh: {
create: null, create: null,