working layers - still needs parallax support

This commit is contained in:
logsol 2014-08-31 17:50:55 +02:00
parent 222fd09f3f
commit a70ca6d8fb
8 changed files with 77 additions and 32 deletions

View file

@ -8,8 +8,8 @@ define([
function (Parent, Settings, Nc, Layer) {
function Item(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
this.layerId = Layer.ID.ITEM;
Parent.call(this, physicsEngine, uid, options);
}
Item.prototype = Object.create(Parent.prototype);

View file

@ -8,8 +8,8 @@ define([
function (Parent, Settings, Nc, Layer) {
function Tile(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
this.layerId = Layer.ID.TILE;
Parent.call(this, physicsEngine, uid, options);
}
Tile.prototype = Object.create(Parent.prototype);

View file

@ -89,13 +89,14 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
};
Level.prototype.createItems = function(options) {
options.layer = AbstractLayer.ID.ITEM;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layer, 1, AbstractLayer.ID.SPAWN, true);
options.layerId = AbstractLayer.ID.ITEM;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
Parent.prototype.createItems.call(this, options);
};
Level.prototype.createTiles = function(options) {
console.log('client level createTiles');
options.layerId = AbstractLayer.ID.TILE;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
@ -106,7 +107,7 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
options.layerId = AbstractLayer.ID.SPAWN;
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1);
Parent.prototype.createTiles.call(this, options);
Parent.prototype.createSpawnPoints.call(this, options);
};
return Level;

View file

@ -6,8 +6,8 @@ define([
function (Parent, Settings) {
function TiledLevel(uid, engine, gameObjects) {
Parent.call(this, uid, engine, gameObjects);
this.layerId = "background";
Parent.call(this, uid, engine, gameObjects);
}
TiledLevel.prototype = Object.create(Parent.prototype);

View file

@ -6,9 +6,9 @@ define([
function (Nc, Exception, Layer) {
function LayerManager(stage) {
function LayerManager(container) {
this.layers = [];
this.stage = stage;
this.container = container;
this.ncTokens = [
Nc.on(Nc.ns.client.view.layer.createAndInsert, this.createAndInsert, this),
@ -40,14 +40,37 @@ function (Nc, Exception, Layer) {
throw new Exception('Reference Layer (' + referenceId + ') could not be found');
}
} else {
referenceIndex = behind ? 0 : this.stage.children.length;
referenceIndex = behind ? 0 : this.container.children.length;
}
var layer = new Layer(id, parallaxSpeed);
var layerIndex = behind ? referenceIndex -1 : referenceIndex;
this.layers.splice(layerIndex, 0, layer);
this.stage.addChildAt(layer.getContainer(), layerIndex);
this.rearrangeLayers();
};
LayerManager.prototype.rearrangeLayers = function() {
var layer;
for (var i = this.layers.length - 1; i >= 0; i--) {
layer = this.layers[i];
if (this.container.children.indexOf(layer.getContainer()) !== -1) {
this.container.removeChild(layer.getContainer());
}
};
if (this.container.children.length !== 0) {
console.warn('Unmanaged stuff in container... ', this.container.children);
//throw new Exception('Unmanaged dirt in container... ');
}
for (var i = 0; i < this.layers.length; i++) {
layer = this.layers[i];
this.container.addChildAt(layer.getContainer(), i);
};
};
LayerManager.prototype.getLayerById = function(id) {
@ -57,42 +80,59 @@ function (Nc, Exception, Layer) {
return layer;
}
};
throw new Exception('No such layer: ' + id);
return null;
};
LayerManager.prototype.delegate = function(methodName, layerId) {
LayerManager.prototype.delegate = function() {
var methodName = arguments[0];
var layerId = arguments[1];
var layer = this.getLayerById(layerId);
var args = Array.prototype.splice.call(arguments, 0, 2);
if (!layer) {
throw new Exception('Layer (' + layerId + ') does not exist.');
}
var args = arguments;
Array.prototype.splice.call(args, 0, 2);
layer[methodName].apply(layer, args);
};
LayerManager.prototype.createMesh = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createMesh'));
var args = arguments;
Array.prototype.splice.call(args, 0, 0, 'createMesh')
this.delegate.apply(this, args);
};
LayerManager.prototype.createAnimatedMesh = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'createAnimatedMesh'));
Array.prototype.splice.call(arguments, 0, 0, 'createAnimatedMesh')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.addMesh = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addMesh'));
Array.prototype.splice.call(arguments, 0, 0, 'addMesh')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.removeMesh = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeMesh'));
Array.prototype.splice.call(arguments, 0, 0, 'removeMesh')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.updateMesh = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'updateMesh'));
Array.prototype.splice.call(arguments, 0, 0, 'updateMesh')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.addFilter = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'addFilter'));
Array.prototype.splice.call(arguments, 0, 0, 'addFilter')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.removeFilter = function() {
this.delegate(Array.prototype.splice.call(arguments, 0, 0, 'removeFilter'));
Array.prototype.splice.call(arguments, 0, 0, 'removeFilter')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.destroy = function() {

View file

@ -1,13 +1,23 @@
define([
"Game/Client/View/Abstract/Layer",
"Lib/Vendor/Pixi",
"Game/Client/View/Pixi/ColorRangeReplaceFilter",
],
function (Parent, PIXI) {
function (Parent, PIXI, ColorRangeReplaceFilter) {
var AVAILABLE_MESH_FILTERS = {
"blur": PIXI.BlurFilter,
"desaturate": PIXI.GrayFilter,
"pixelate": PIXI.PixelateFilter,
"colorRangeReplace": ColorRangeReplaceFilter,
};
function Layer (name, parallaxSpeed) {
Parent.call(this, name, parallaxSpeed);
this.container = new PIXI.DisplayObjectContainer();
this.container.x = 0;
this.container.y = 0;
}
Layer.prototype = Object.create(Parent.prototype);

View file

@ -2,7 +2,6 @@ define([
"Game/Client/View/Abstract/View",
"Game/Client/View/DomController",
"Lib/Vendor/Pixi",
"Game/Client/View/Pixi/ColorRangeReplaceFilter",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception",
@ -10,14 +9,7 @@ define([
"Game/Client/View/LayerManager",
],
function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Exception, GameStats, LayerManager) {
var AVAILABLE_MESH_FILTERS = {
"blur": PIXI.BlurFilter,
"desaturate": PIXI.GrayFilter,
"pixelate": PIXI.PixelateFilter,
"colorRangeReplace": ColorRangeReplaceFilter,
};
function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager) {
function PixiView () {
@ -56,9 +48,10 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
this.stage = new PIXI.Stage(0x333333);
this.layerManager = new LayerManager(this.stage);
this.initCamera();
this.layerManager = new LayerManager(this.container);
this.initLoader();
this.initCanvas(this.renderer.view);