diff --git a/app/Game/Client/View/Abstract/View.js b/app/Game/Client/View/Abstract/View.js index 6ff4f23..409b976 100755 --- a/app/Game/Client/View/Abstract/View.js +++ b/app/Game/Client/View/Abstract/View.js @@ -21,9 +21,6 @@ function (Abstract, DomController, Settings, Exception, Nc) { Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, this), Nc.on(Nc.ns.client.view.playerInfo.remove, this.onRemovePlayerInfo, this), - Nc.on(Nc.ns.client.view.playerArrow.createAndAdd, this.onCreateAndAddPlayerArrow, this), - Nc.on(Nc.ns.client.view.playerArrow.update, this.onUpdatePlayerArrow, this), - Nc.on(Nc.ns.client.game.zoomIn, this.onZoomIn, this), Nc.on(Nc.ns.client.game.zoomOut, this.onZoomOut, this), Nc.on(Nc.ns.client.game.zoomReset, this.onZoomReset, this), @@ -41,8 +38,6 @@ function (Abstract, DomController, Settings, Exception, Nc) { Abstract.prototype.addMethod.call(AbstractView, 'onZoomReset'); Abstract.prototype.addMethod.call(AbstractView, 'toggleInfo', ['show', 'string']); Abstract.prototype.addMethod.call(AbstractView, 'onCreateAndAddPlayerInfo', ['options']); - Abstract.prototype.addMethod.call(AbstractView, 'onCreateAndAddPlayerArrow', ['options']); - Abstract.prototype.addMethod.call(AbstractView, 'onUpdatePlayerArrow', ['options']); Abstract.prototype.addMethod.call(AbstractView, 'onUpdatePlayerInfo', ['mesh', 'options']); Abstract.prototype.addMethod.call(AbstractView, 'onRemovePlayerInfo', ['mesh']); Abstract.prototype.addMethod.call(AbstractView, 'onUpdateLoader', ['progress']); diff --git a/app/Game/Client/View/LayerManager.js b/app/Game/Client/View/LayerManager.js index 1a9433e..7aeaad7 100644 --- a/app/Game/Client/View/LayerManager.js +++ b/app/Game/Client/View/LayerManager.js @@ -35,7 +35,11 @@ function (Nc, Exception, Layer) { * or in the foreground (behind=false/null) */ LayerManager.prototype.createAndInsert = function(id, parallaxSpeed, behind, referenceId) { + var layer = new Layer(id, parallaxSpeed); + this.insert(layer, behind, referenceId); + }; + LayerManager.prototype.insert = function(newlayer, behind, referenceId) { var referenceIndex = -1; behind = !!behind; @@ -55,10 +59,9 @@ function (Nc, Exception, Layer) { referenceIndex = behind ? 0 : this.container.children.length; } - var layer = new Layer(id, parallaxSpeed); var layerIndex = behind ? referenceIndex : referenceIndex + 1; - this.layers.splice(layerIndex, 0, layer); + this.layers.splice(layerIndex, 0, newlayer); this.rearrangeLayers(); }; diff --git a/app/Game/Client/View/Pixi/Layers/Ghost.js b/app/Game/Client/View/Pixi/Layers/Ghost.js new file mode 100644 index 0000000..b00375d --- /dev/null +++ b/app/Game/Client/View/Pixi/Layers/Ghost.js @@ -0,0 +1,73 @@ +define([ + "Game/Client/View/Pixi/Layer", + "Lib/Vendor/Pixi", + "Lib/Utilities/NotificationCenter", + "Game/Config/Settings" +], + +function (Parent, PIXI, Nc, Settings) { + + function Ghost() { + Parent.call(this, "ghost", 0); + + this.ncTokens = [ + Nc.on(Nc.ns.client.view.playerArrow.createAndAdd, this.onCreateAndAddPlayerArrow, this), + Nc.on(Nc.ns.client.view.playerArrow.update, this.onUpdatePlayerArrow, this) + ]; + + } + + Ghost.prototype = Object.create(Parent.prototype); + + Ghost.prototype.onCreateAndAddPlayerArrow = function(callback, options) { + + var arrow = new PIXI.Graphics(); + arrow.visible = false; + this.container.addChild(arrow); + + var width = 12, + height = 12; + + arrow.beginFill(0xffffff, 0.1); + arrow.lineStyle(0, 0x000000); + arrow.moveTo(0, 0); + arrow.lineTo(width, 0); + arrow.lineTo(width / 2, height); + arrow.endFill(); + arrow.pivot = new PIXI.Point(width/2, height/2); + arrow.visible = true; + + this.onUpdatePlayerArrow(arrow, options); + + callback(arrow); + }; + + Ghost.prototype.onUpdatePlayerArrow = function(arrow, options) { + + var offsetX = 0, + offsetY = -60, + x = offsetX + options.x, + y = offsetY + options.y; + + var target = new PIXI.Point(x, y); + + arrow.position.x += (target.x -arrow.position.x) * Settings.ARROW_GLIDE / 1.5 / 100; + arrow.position.y += (target.y -arrow.position.y) * Settings.ARROW_GLIDE / 100; + + var angle = -Math.atan2(arrow.position.x - x, arrow.position.y - options.y); + angle += 0.785398163 * 4; + + arrow.rotation = angle; + }; + + + + Ghost.prototype.destroy = function() { + for (var i = 0; i < this.ncTokens.length; i++) { + Nc.off(this.ncTokens[i]); + }; + }; + + return Ghost; + +}); \ No newline at end of file diff --git a/app/Game/Client/View/Pixi/View.js b/app/Game/Client/View/Pixi/View.js index 3917099..c381fc4 100755 --- a/app/Game/Client/View/Pixi/View.js +++ b/app/Game/Client/View/Pixi/View.js @@ -7,26 +7,25 @@ define([ "Lib/Utilities/Exception", "Game/Client/View/Pixi/GameStats", "Game/Client/View/LayerManager", + "Game/Client/View/Pixi/Layers/Ghost" ], -function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager) { +function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager, Ghost) { function PixiView () { Parent.call(this); this.layerManager = null; - this.movableObjects = []; this.stage = null; this.container = null; this.infoContainer = null; this.infoFilters = []; - this.infoBox = null; this.loader = null; - this.init(); - this.pixi = PIXI; this.currentZoom = Settings.ZOOM_DEFAULT; + this.init(); + PIXI.scaleModes.DEFAULT = PIXI.scaleModes.NEAREST; } @@ -59,6 +58,9 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer this.gameStats = new GameStats(this.container); this.stage.addChild(this.gameStats.getInfoContainer()); + + this.ghostLayer = new Ghost(); + this.layerManager.insert(this.ghostLayer, false); } PixiView.prototype.render = function () { @@ -142,45 +144,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer }; - PixiView.prototype.onCreateAndAddPlayerArrow = function(callback, options) { - var arrow = new PIXI.Graphics(); - arrow.visible = false; - this.container.addChild(arrow); - var width = 12, - height = 12; - - arrow.beginFill(0xffffff, 0.1); - arrow.lineStyle(0, 0x000000); - arrow.moveTo(0, 0); - arrow.lineTo(width, 0); - arrow.lineTo(width / 2, height); - arrow.endFill(); - arrow.pivot = new PIXI.Point(width/2, height/2); - arrow.visible = true; - - this.onUpdatePlayerArrow(arrow, options); - - callback(arrow); - }; - - PixiView.prototype.onUpdatePlayerArrow = function(arrow, options) { - - var offsetX = 0, - offsetY = -60, - x = offsetX + options.x, - y = offsetY + options.y; - - var target = new PIXI.Point(x, y); - - arrow.position.x += (target.x -arrow.position.x) * Settings.ARROW_GLIDE / 1.5 / 100; - arrow.position.y += (target.y -arrow.position.y) * Settings.ARROW_GLIDE / 100; - - var angle = -Math.atan2(arrow.position.x - x, arrow.position.y - options.y); - angle += 0.785398163 * 4; - - arrow.rotation = angle; - }; PixiView.prototype.initLoader = function() { this.loader = new PIXI.Graphics(); @@ -238,6 +202,8 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer PixiView.prototype.destroy = function() { this.layerManager.destroy(); + + this.ghostLayer.destroy(); for (var i = 0; i < this.stage.children.length; i++) { this.stage.removeChild(this.stage.children[i]); diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index bd31115..91f6aa7 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -72,6 +72,7 @@ define([ continue; } + // Setting up spawnpoints and then all layers behind it this.setupLayer(layerOptions, true, lastLayerId); if(this.layerMapping[layerOptions.name]) { @@ -100,6 +101,7 @@ define([ continue; } + // Setting up all layers before this.setupLayer(layerOptions, false, lastLayerId); if(this.layerMapping[layerOptions.name]) {