mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
working layers - still needs parallax support
This commit is contained in:
parent
222fd09f3f
commit
a70ca6d8fb
8 changed files with 77 additions and 32 deletions
|
|
@ -8,8 +8,8 @@ define([
|
||||||
function (Parent, Settings, Nc, Layer) {
|
function (Parent, Settings, Nc, Layer) {
|
||||||
|
|
||||||
function Item(physicsEngine, uid, options) {
|
function Item(physicsEngine, uid, options) {
|
||||||
Parent.call(this, physicsEngine, uid, options);
|
|
||||||
this.layerId = Layer.ID.ITEM;
|
this.layerId = Layer.ID.ITEM;
|
||||||
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.prototype = Object.create(Parent.prototype);
|
Item.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ define([
|
||||||
function (Parent, Settings, Nc, Layer) {
|
function (Parent, Settings, Nc, Layer) {
|
||||||
|
|
||||||
function Tile(physicsEngine, uid, options) {
|
function Tile(physicsEngine, uid, options) {
|
||||||
Parent.call(this, physicsEngine, uid, options);
|
|
||||||
this.layerId = Layer.ID.TILE;
|
this.layerId = Layer.ID.TILE;
|
||||||
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile.prototype = Object.create(Parent.prototype);
|
Tile.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -89,13 +89,14 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Level.prototype.createItems = function(options) {
|
Level.prototype.createItems = function(options) {
|
||||||
options.layer = AbstractLayer.ID.ITEM;
|
options.layerId = 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.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
|
||||||
|
|
||||||
Parent.prototype.createItems.call(this, options);
|
Parent.prototype.createItems.call(this, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
Level.prototype.createTiles = function(options) {
|
Level.prototype.createTiles = function(options) {
|
||||||
|
console.log('client level createTiles');
|
||||||
options.layerId = AbstractLayer.ID.TILE;
|
options.layerId = 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.createAndInsert, options.layerId, 1, AbstractLayer.ID.SPAWN, true);
|
||||||
|
|
||||||
|
|
@ -106,7 +107,7 @@ function (Parent, Settings, Nc, PIXI, AbstractLayer) {
|
||||||
options.layerId = AbstractLayer.ID.SPAWN;
|
options.layerId = AbstractLayer.ID.SPAWN;
|
||||||
Nc.trigger(Nc.ns.client.view.layer.createAndInsert, options.layerId, 1);
|
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;
|
return Level;
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ define([
|
||||||
function (Parent, Settings) {
|
function (Parent, Settings) {
|
||||||
|
|
||||||
function TiledLevel(uid, engine, gameObjects) {
|
function TiledLevel(uid, engine, gameObjects) {
|
||||||
Parent.call(this, uid, engine, gameObjects);
|
|
||||||
this.layerId = "background";
|
this.layerId = "background";
|
||||||
|
Parent.call(this, uid, engine, gameObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
TiledLevel.prototype = Object.create(Parent.prototype);
|
TiledLevel.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ define([
|
||||||
|
|
||||||
function (Nc, Exception, Layer) {
|
function (Nc, Exception, Layer) {
|
||||||
|
|
||||||
function LayerManager(stage) {
|
function LayerManager(container) {
|
||||||
this.layers = [];
|
this.layers = [];
|
||||||
this.stage = stage;
|
this.container = container;
|
||||||
|
|
||||||
this.ncTokens = [
|
this.ncTokens = [
|
||||||
Nc.on(Nc.ns.client.view.layer.createAndInsert, this.createAndInsert, this),
|
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');
|
throw new Exception('Reference Layer (' + referenceId + ') could not be found');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
referenceIndex = behind ? 0 : this.stage.children.length;
|
referenceIndex = behind ? 0 : this.container.children.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
var layer = new Layer(id, parallaxSpeed);
|
var layer = new Layer(id, parallaxSpeed);
|
||||||
var layerIndex = behind ? referenceIndex -1 : referenceIndex;
|
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.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) {
|
LayerManager.prototype.getLayerById = function(id) {
|
||||||
|
|
@ -57,42 +80,59 @@ function (Nc, Exception, Layer) {
|
||||||
return 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 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);
|
layer[methodName].apply(layer, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
LayerManager.prototype.createMesh = function() {
|
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() {
|
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() {
|
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() {
|
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() {
|
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() {
|
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() {
|
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() {
|
LayerManager.prototype.destroy = function() {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,23 @@
|
||||||
define([
|
define([
|
||||||
"Game/Client/View/Abstract/Layer",
|
"Game/Client/View/Abstract/Layer",
|
||||||
"Lib/Vendor/Pixi",
|
"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) {
|
function Layer (name, parallaxSpeed) {
|
||||||
Parent.call(this, name, parallaxSpeed);
|
Parent.call(this, name, parallaxSpeed);
|
||||||
this.container = new PIXI.DisplayObjectContainer();
|
this.container = new PIXI.DisplayObjectContainer();
|
||||||
|
this.container.x = 0;
|
||||||
|
this.container.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer.prototype = Object.create(Parent.prototype);
|
Layer.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ define([
|
||||||
"Game/Client/View/Abstract/View",
|
"Game/Client/View/Abstract/View",
|
||||||
"Game/Client/View/DomController",
|
"Game/Client/View/DomController",
|
||||||
"Lib/Vendor/Pixi",
|
"Lib/Vendor/Pixi",
|
||||||
"Game/Client/View/Pixi/ColorRangeReplaceFilter",
|
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"Lib/Utilities/NotificationCenter",
|
||||||
"Lib/Utilities/Exception",
|
"Lib/Utilities/Exception",
|
||||||
|
|
@ -10,14 +9,7 @@ define([
|
||||||
"Game/Client/View/LayerManager",
|
"Game/Client/View/LayerManager",
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Exception, GameStats, LayerManager) {
|
function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager) {
|
||||||
|
|
||||||
var AVAILABLE_MESH_FILTERS = {
|
|
||||||
"blur": PIXI.BlurFilter,
|
|
||||||
"desaturate": PIXI.GrayFilter,
|
|
||||||
"pixelate": PIXI.PixelateFilter,
|
|
||||||
"colorRangeReplace": ColorRangeReplaceFilter,
|
|
||||||
};
|
|
||||||
|
|
||||||
function PixiView () {
|
function PixiView () {
|
||||||
|
|
||||||
|
|
@ -56,9 +48,10 @@ 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.layerManager = new LayerManager(this.container);
|
||||||
|
|
||||||
this.initLoader();
|
this.initLoader();
|
||||||
|
|
||||||
this.initCanvas(this.renderer.view);
|
this.initCanvas(this.renderer.view);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
TiledLevel.prototype.createTiles = function(options) {
|
TiledLevel.prototype.createTiles = function(options) {
|
||||||
|
console.log('core tiledlevel createTiles');
|
||||||
|
|
||||||
var data = options.data;
|
var data = options.data;
|
||||||
var tilesOptions = [];
|
var tilesOptions = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue