Commit b5cf2632 authored by 汪欢's avatar 汪欢

拼图长按bug

parent 634f2330
......@@ -56,14 +56,14 @@ function launchWithCustomModule(customModule) {
engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000);
setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
// picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
blockUrl: "888"
});
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('pictures-start', {
// picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
// // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
// blockUrl: "888"
// });
}, 30*1000);
// }, 30*1000);
});
engine.globalEvent.addEventListener('pictures-time-update', (e) => {
// console.log(e.type, e.data);
......
......@@ -100,7 +100,7 @@
var _this = this;
if (!this.guideHole) {
this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl;
this.guideHole.source = "asset://" + props.blockUrl;
this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;
}
if (this.pictures) {
......@@ -110,8 +110,8 @@
pic.parent.removeChild(pic);
}
}
console.log('on start');
engine.globalEvent.dispatchEvent('pictures-time-update', {
console.log("on start");
engine.globalEvent.dispatchEvent("pictures-time-update", {
second: this.getSecond(),
});
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
......@@ -140,16 +140,17 @@
GAME_TIME = this.afterPointTwo(GAME_TIME);
GAME_TIME = GAME_TIME.toFixed(2);
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(),
});
if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME;
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
engine.globalEvent.dispatchEvent("pictures-game-fail", {
reason: 1,
});
}
};
......@@ -166,6 +167,7 @@
};
GameView.prototype.stop = function () {
clearInterval(this._timer);
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
var len = this.pictures.length;
for (var i = 0; i < len; i++) {
this.pictures[i].removeAllEventListener();
......@@ -181,7 +183,7 @@
GAP = props.GAP;
w = W / MAX_COL;
h = H / MAX_ROW;
console.log('onSteup', props);
console.log("onSteup", props);
var parent = new engine.Sprite();
this.picturesWrapper = parent;
this.addChild(parent);
......@@ -195,67 +197,72 @@
this.localPicY = e.localY / MAX_ROW;
this.distanceX = this.dragPic.x;
this.distanceY = this.dragPic.y;
this.indexJ = Math.floor((this.distanceX) / (w + GAP));
this.indexI = Math.floor((this.distanceY) / (h + GAP));
this.index = (this.indexI) * MAX_COL + this.indexJ;
this.indexJ = Math.floor(this.distanceX / (w + GAP));
this.indexI = Math.floor(this.distanceY / (h + GAP));
this.index = this.indexI * MAX_COL + this.indexJ;
this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 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_UP, this.stageOnUp, this);
};
GameView.prototype.stageOnUp = function (e) {
var stageLeft = (750 - props.W) / 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_UP, this.stageOnUp, this);
if (this.centerY < stageTop || this.centerX < stageLeft) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var curJ = Math.floor(this.centerX / (w + GAP));
var curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole);
if (0 <= curJ && curJ < (MAX_COL) && 0 <= curI && curI < (MAX_ROW)) {
var index = getIndexFromRC(curI, curJ, MAX_COL);
var dropPic = this.pictures[index];
var dropPicX = dropPic.x + stageLeft;
var dropPicy = dropPic.y + stageTop;
dropPic.x = this.distanceX;
dropPic.y = this.distanceY;
this.dragPic.x = dropPicX - stageLeft;
this.dragPic.y = dropPicy - stageTop;
var dropPicIndex = this.pictures.indexOf(dropPic);
var dragPicIndex = this.pictures.indexOf(this.dragPic);
this.pictures[dropPicIndex] = this.dragPic;
this.pictures[dragPicIndex] = dropPic;
if (dragPicIndex === dropPicIndex) {
GameView.prototype.stageOnUp = function () {
if (GAME_TIME > 0) {
var stageLeft = (750 - props.W) / 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_UP, this.stageOnUp, this);
if (this.centerY < stageTop || this.centerX < stageLeft) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var result = true;
for (var j = 0; j < this.rightList.length; j++) {
if (this.rightList[j] != this.pictures[j]) {
result = false;
break;
var curJ = Math.floor(this.centerX / (w + GAP));
var curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole);
if (0 <= curJ && curJ < MAX_COL && 0 <= curI && curI < MAX_ROW) {
var index = getIndexFromRC(curI, curJ, MAX_COL);
var dropPic = this.pictures[index];
var dropPicX = dropPic.x + stageLeft;
var dropPicy = dropPic.y + stageTop;
dropPic.x = this.distanceX;
dropPic.y = this.distanceY;
this.dragPic.x = dropPicX - stageLeft;
this.dragPic.y = dropPicy - stageTop;
var dropPicIndex = this.pictures.indexOf(dropPic);
var dragPicIndex = this.pictures.indexOf(this.dragPic);
this.pictures[dropPicIndex] = this.dragPic;
this.pictures[dragPicIndex] = dropPic;
if (dragPicIndex === dropPicIndex) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var result = true;
for (var j = 0; j < this.rightList.length; j++) {
if (this.rightList[j] != this.pictures[j]) {
result = false;
break;
}
}
if (result) {
this.onSuccess();
}
}
if (result) {
this.onSuccess();
else {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
}
else {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
};
GameView.prototype.onSuccess = function () {
console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });
console.log("拼图成功!");
engine.globalEvent.dispatchEvent("pictures-game-success", {
time: GAME_TIME,
});
this.stop();
};
GameView.prototype.onMove = function (e) {
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.centerY = this.dragPic.y + h / 2;
};
......
This diff is collapsed.
......@@ -40,7 +40,7 @@
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 50
"default": 5
}
},
......
......@@ -124,12 +124,20 @@ export default class GameView extends engine.Container {
}
stop() {
// GAME_TIME = props.GAME_TIME
clearInterval(this._timer);
let len = this.pictures.length;
for(let i=0;i<len;i++){
this.pictures[i].removeAllEventListener();
}
this.stage.removeEventListener(
engine.MouseEvent.MOUSE_UP,
this.stageOnUp,
this
);
}
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