From 1e233efbeaaa9f50e24786578b6816aa8b3795f9 Mon Sep 17 00:00:00 2001 From: logsol Date: Mon, 8 Dec 2014 19:36:14 +0100 Subject: [PATCH] Added Swiper drawing --- .../Client/Control/Inputs/KeyboardAndMouse.js | 1 - app/Game/Client/Control/Swiper.js | 18 +++++- app/Game/Client/Me.js | 2 +- app/Game/Client/View/Pixi/Layers/Swiper.js | 56 +++++++++++++++++++ app/Game/Client/View/Pixi/View.js | 11 +++- app/Lib/Utilities/NotificationCenter.js | 4 ++ 6 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 app/Game/Client/View/Pixi/Layers/Swiper.js diff --git a/app/Game/Client/Control/Inputs/KeyboardAndMouse.js b/app/Game/Client/Control/Inputs/KeyboardAndMouse.js index 191f7bf..74f9a2e 100644 --- a/app/Game/Client/Control/Inputs/KeyboardAndMouse.js +++ b/app/Game/Client/Control/Inputs/KeyboardAndMouse.js @@ -104,7 +104,6 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { canvas.onmouseup = function(e) { if(self.swiper) { - console.log(e) var xya = self.swiper.swipeEnd(e.x, e.y); self.playerController.handActionRequest(xya.x, xya.y); self.swiper = null; diff --git a/app/Game/Client/Control/Swiper.js b/app/Game/Client/Control/Swiper.js index 9e42d28..a83235f 100644 --- a/app/Game/Client/Control/Swiper.js +++ b/app/Game/Client/Control/Swiper.js @@ -1,9 +1,10 @@ define([ + "Lib/Utilities/NotificationCenter", ], -function () { +function (Nc) { - var MAX_LENGTH = 300; + var MAX_LENGTH = 150; function Swiper() { this.points = []; @@ -12,11 +13,14 @@ function () { } Swiper.prototype.swipe = function(x, y) { - console.log("swipe") + if(this.lengthSum > MAX_LENGTH) return; this.points.push({x:x, y:y}); + + Nc.trigger(Nc.ns.client.view.swiper.swipe, x, y); + var points = this.points; if(points.length >= 3) { @@ -77,6 +81,8 @@ function () { var p0y = this.points[0].y; var sumx = 0; var sumy = 0; + + Nc.trigger(Nc.ns.client.view.swiper.end); for(var i=0, count = this.points.length; i < count; i++) { var p = this.points[i]; @@ -103,6 +109,12 @@ function () { spin: spin } } + + Swiper.prototype.destroy = function() { + for (var i = 0; i < this.ncTokens.length; i++) { + Nc.off(this.ncTokens[i]); + }; + }; return Swiper; diff --git a/app/Game/Client/Me.js b/app/Game/Client/Me.js index cfa6b15..60ae102 100644 --- a/app/Game/Client/Me.js +++ b/app/Game/Client/Me.js @@ -11,7 +11,7 @@ function (Parent, Settings, Nc) { // View uses this to calculate center position this.lookAtXY = { - x: 1, + x: 0.3, y: 0 } diff --git a/app/Game/Client/View/Pixi/Layers/Swiper.js b/app/Game/Client/View/Pixi/Layers/Swiper.js new file mode 100644 index 0000000..2d6f185 --- /dev/null +++ b/app/Game/Client/View/Pixi/Layers/Swiper.js @@ -0,0 +1,56 @@ +define([ + "Game/Client/View/Pixi/Layer", + "Lib/Vendor/Pixi", + "Lib/Utilities/NotificationCenter", + "Game/Config/Settings" +], + +function (Parent, PIXI, Nc, Settings) { + + function Swiper() { + Parent.call(this, "ghost", 0); + + this.ncTokens = [ + Nc.on(Nc.ns.client.view.swiper.swipe, this.swipe, this), + Nc.on(Nc.ns.client.view.swiper.end, this.end, this) + ]; + + this.offset = { + x: Settings.STAGE_WIDTH / 2, + y: Settings.STAGE_HEIGHT / 2 + } + + this.sprite = new PIXI.Graphics(); + this.container.addChild(this.sprite); + + this.end(); + } + + Swiper.prototype = Object.create(Parent.prototype); + + Swiper.prototype.swipe = function(x, y) { + + this.sprite.moveTo(this.offset.x + this.last.x, this.offset.y + this.last.y); + + this.last.x += x; + this.last.y -= y; + + this.sprite.lineTo(this.offset.x + this.last.x, this.offset.y + this.last.y); + }; + + Swiper.prototype.end = function(x, y) { + this.sprite.clear(); + + this.sprite.lineStyle(2, 0xffffff); + this.sprite.alpha = 0.5; + + this.last = { + x: 0, + y: 0 + } + }; + + + return Swiper; + +}); \ 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 654b683..901fa22 100755 --- a/app/Game/Client/View/Pixi/View.js +++ b/app/Game/Client/View/Pixi/View.js @@ -7,10 +7,11 @@ define([ "Lib/Utilities/Exception", "Game/Client/View/Pixi/GameStats", "Game/Client/View/LayerManager", - "Game/Client/View/Pixi/Layers/Ghost" + "Game/Client/View/Pixi/Layers/Ghost", + "Game/Client/View/Pixi/Layers/Swiper" ], -function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager, Ghost) { +function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager, Ghost, Swiper) { function PixiView () { @@ -56,11 +57,16 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer this.initCanvas(this.renderer.view); + // Tab Overlay (not using layer manager) this.gameStats = new GameStats(this.container); this.stage.addChild(this.gameStats.getInfoContainer()); this.ghostLayer = new Ghost(); this.layerManager.insert(this.ghostLayer, false); + + this.swiperLayer = new Swiper(); + this.stage.addChild(this.swiperLayer.getContainer()); + //this.layerManager.insert(this.swiperLayer, false); } PixiView.prototype.render = function () { @@ -157,6 +163,7 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer this.layerManager.destroy(); this.ghostLayer.destroy(); + this.swiperLayer.destroy(); for (var i = 0; i < this.stage.children.length; i++) { this.stage.removeChild(this.stage.children[i]); diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index 126faf7..e539a1e 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -62,6 +62,10 @@ function (Exception) { }, gameStats: { toggle: null + }, + swiper: { + swipe: null, + end: null } }, input: {