mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Added Swiper drawing
This commit is contained in:
parent
cf2182676b
commit
1e233efbea
6 changed files with 85 additions and 7 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ function (Parent, Settings, Nc) {
|
|||
|
||||
// View uses this to calculate center position
|
||||
this.lookAtXY = {
|
||||
x: 1,
|
||||
x: 0.3,
|
||||
y: 0
|
||||
}
|
||||
|
||||
|
|
|
|||
56
app/Game/Client/View/Pixi/Layers/Swiper.js
Normal file
56
app/Game/Client/View/Pixi/Layers/Swiper.js
Normal file
|
|
@ -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;
|
||||
|
||||
});
|
||||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ function (Exception) {
|
|||
},
|
||||
gameStats: {
|
||||
toggle: null
|
||||
},
|
||||
swiper: {
|
||||
swipe: null,
|
||||
end: null
|
||||
}
|
||||
},
|
||||
input: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue