Commit b5cf2632 authored by 汪欢's avatar 汪欢

拼图长按bug

parent 634f2330
...@@ -56,14 +56,14 @@ function launchWithCustomModule(customModule) { ...@@ -56,14 +56,14 @@ function launchWithCustomModule(customModule) {
engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2; engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000); }, 1000);
setTimeout(() => { // setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', { // engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png", // picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
// picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png" // // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
blockUrl: "888" // blockUrl: "888"
}); // });
}, 30*1000); // }, 30*1000);
}); });
engine.globalEvent.addEventListener('pictures-time-update', (e) => { engine.globalEvent.addEventListener('pictures-time-update', (e) => {
// console.log(e.type, e.data); // console.log(e.type, e.data);
......
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
var _this = this; var _this = this;
if (!this.guideHole) { if (!this.guideHole) {
this.guideHole = new engine.Image(); this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl; this.guideHole.source = "asset://" + props.blockUrl;
this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false; this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;
} }
if (this.pictures) { if (this.pictures) {
...@@ -110,8 +110,8 @@ ...@@ -110,8 +110,8 @@
pic.parent.removeChild(pic); pic.parent.removeChild(pic);
} }
} }
console.log('on start'); console.log("on start");
engine.globalEvent.dispatchEvent('pictures-time-update', { engine.globalEvent.dispatchEvent("pictures-time-update", {
second: this.getSecond(), second: this.getSecond(),
}); });
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW); var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
...@@ -140,16 +140,17 @@ ...@@ -140,16 +140,17 @@
GAME_TIME = this.afterPointTwo(GAME_TIME); GAME_TIME = this.afterPointTwo(GAME_TIME);
GAME_TIME = GAME_TIME.toFixed(2); GAME_TIME = GAME_TIME.toFixed(2);
if (GAME_TIME < 10) { if (GAME_TIME < 10) {
GAME_TIME = '0' + GAME_TIME; GAME_TIME = "0" + GAME_TIME;
} }
engine.globalEvent.dispatchEvent('pictures-time-update', { console.log(GAME_TIME);
engine.globalEvent.dispatchEvent("pictures-time-update", {
second: this.getSecond(), second: this.getSecond(),
}); });
if (this.getSecond() == 0) { if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME; GAME_TIME = props.GAME_TIME;
this.stop(); this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', { engine.globalEvent.dispatchEvent("pictures-game-fail", {
reason: 1 reason: 1,
}); });
} }
}; };
...@@ -166,6 +167,7 @@ ...@@ -166,6 +167,7 @@
}; };
GameView.prototype.stop = function () { GameView.prototype.stop = function () {
clearInterval(this._timer); clearInterval(this._timer);
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
var len = this.pictures.length; var len = this.pictures.length;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
this.pictures[i].removeAllEventListener(); this.pictures[i].removeAllEventListener();
...@@ -181,7 +183,7 @@ ...@@ -181,7 +183,7 @@
GAP = props.GAP; GAP = props.GAP;
w = W / MAX_COL; w = W / MAX_COL;
h = H / MAX_ROW; h = H / MAX_ROW;
console.log('onSteup', props); console.log("onSteup", props);
var parent = new engine.Sprite(); var parent = new engine.Sprite();
this.picturesWrapper = parent; this.picturesWrapper = parent;
this.addChild(parent); this.addChild(parent);
...@@ -195,15 +197,16 @@ ...@@ -195,15 +197,16 @@
this.localPicY = e.localY / MAX_ROW; this.localPicY = e.localY / MAX_ROW;
this.distanceX = this.dragPic.x; this.distanceX = this.dragPic.x;
this.distanceY = this.dragPic.y; this.distanceY = this.dragPic.y;
this.indexJ = Math.floor((this.distanceX) / (w + GAP)); this.indexJ = Math.floor(this.distanceX / (w + GAP));
this.indexI = Math.floor((this.distanceY) / (h + GAP)); this.indexI = Math.floor(this.distanceY / (h + GAP));
this.index = (this.indexI) * MAX_COL + this.indexJ; this.index = this.indexI * MAX_COL + this.indexJ;
this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 2; this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 2;
this.centerY = Math.floor((e.clientY - stageTop) / h) * h + h / 2; this.centerY = Math.floor((e.clientY - stageTop) / h) * h + h / 2;
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this); this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this); this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
}; };
GameView.prototype.stageOnUp = function (e) { GameView.prototype.stageOnUp = function () {
if (GAME_TIME > 0) {
var stageLeft = (750 - props.W) / 2; var stageLeft = (750 - props.W) / 2;
var stageTop = (this.stage.height - props.H) / 2; var stageTop = (this.stage.height - props.H) / 2;
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this); this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
...@@ -215,7 +218,7 @@ ...@@ -215,7 +218,7 @@
var curJ = Math.floor(this.centerX / (w + GAP)); var curJ = Math.floor(this.centerX / (w + GAP));
var curI = Math.floor(this.centerY / (h + GAP)); var curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole); this.picturesWrapper.addChild(this.guideHole);
if (0 <= curJ && curJ < (MAX_COL) && 0 <= curI && curI < (MAX_ROW)) { if (0 <= curJ && curJ < MAX_COL && 0 <= curI && curI < MAX_ROW) {
var index = getIndexFromRC(curI, curJ, MAX_COL); var index = getIndexFromRC(curI, curJ, MAX_COL);
var dropPic = this.pictures[index]; var dropPic = this.pictures[index];
var dropPicX = dropPic.x + stageLeft; var dropPicX = dropPic.x + stageLeft;
...@@ -247,15 +250,19 @@ ...@@ -247,15 +250,19 @@
this.dragPic.x = this.distanceX; this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY; this.dragPic.y = this.distanceY;
} }
}
}; };
GameView.prototype.onSuccess = function () { GameView.prototype.onSuccess = function () {
console.log('拼图成功!'); console.log("拼图成功!");
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME }); engine.globalEvent.dispatchEvent("pictures-game-success", {
time: GAME_TIME,
});
this.stop(); this.stop();
}; };
GameView.prototype.onMove = function (e) { GameView.prototype.onMove = function (e) {
this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2; this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2; this.dragPic.y =
e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
this.centerX = this.dragPic.x + w / 2; this.centerX = this.dragPic.x + w / 2;
this.centerY = this.dragPic.y + h / 2; this.centerY = this.dragPic.y + h / 2;
}; };
......
This diff is collapsed.
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
"GAME_TIME": { "GAME_TIME": {
"alias": "游戏时间", "alias": "游戏时间",
"type": "number", "type": "number",
"default": 50 "default": 5
} }
}, },
......
...@@ -124,12 +124,20 @@ export default class GameView extends engine.Container { ...@@ -124,12 +124,20 @@ export default class GameView extends engine.Container {
} }
stop() { stop() {
// GAME_TIME = props.GAME_TIME // GAME_TIME = props.GAME_TIME
clearInterval(this._timer); clearInterval(this._timer);
let len = this.pictures.length; let len = this.pictures.length;
for(let i=0;i<len;i++){ for(let i=0;i<len;i++){
this.pictures[i].removeAllEventListener(); this.pictures[i].removeAllEventListener();
} }
this.stage.removeEventListener(
engine.MouseEvent.MOUSE_UP,
this.stageOnUp,
this
);
} }
constructor() { constructor() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment