110 lines
3.7 KiB
JavaScript
110 lines
3.7 KiB
JavaScript
cc.Class({
|
|
extends: cc.Component,
|
|
properties: {
|
|
rightItem: cc.Node,
|
|
otherItems: {
|
|
type: cc.Node,
|
|
default: []
|
|
},
|
|
startTime: {
|
|
default: 0,
|
|
displayName: "起始延迟时间"
|
|
},
|
|
targetScale: {
|
|
displayName: "点击后放大到多少",
|
|
default: .65
|
|
},
|
|
cankaoItem: {
|
|
type: cc.Node,
|
|
displayName: "要移动到的位置",
|
|
default: null
|
|
},
|
|
eventNode_over: {
|
|
default: null,
|
|
type: cc.Node,
|
|
displayName: "移动完成事件节点"
|
|
},
|
|
eventNode_over2: {
|
|
default: null,
|
|
type: cc.Node,
|
|
displayName: "移动完成的清况2"
|
|
},
|
|
isshow: {
|
|
default: true,
|
|
displayName: "移动到指定位置后的状态"
|
|
}
|
|
},
|
|
onLoad: function () {
|
|
if (this.rightItem) {
|
|
this.rightItem.on(cc.Node.EventType.TOUCH_START, this.onMoveStart, this);
|
|
this.rightItem.on(cc.Node.EventType.TOUCH_MOVE, this.onMove, this);
|
|
this.rightItem.on(cc.Node.EventType.TOUCH_END, this.onMoveEnd, this);
|
|
}
|
|
this.originPos = this.rightItem.getPosition();
|
|
this.originScale = this.rightItem.scale;
|
|
},
|
|
start: function () {},
|
|
onMoveStart: function (e) {
|
|
e.target.scale = this.targetScale;
|
|
e.target.moveStartX = e.target.x;
|
|
e.target.moveStartY = e.target.y;
|
|
this.node.parent.getChildByName("hand_zhiyin") && 1 == this.node.parent.getChildByName("hand_zhiyin").active && (this.node.parent.getChildByName("hand_zhiyin").active = false);
|
|
},
|
|
onMove: function (e) {
|
|
var o = e.getStartLocation();
|
|
var t = e.getLocation();
|
|
e.target.x = e.target.moveStartX + t.x - o.x;
|
|
e.target.y = e.target.moveStartY + t.y - o.y;
|
|
},
|
|
onMoveEndBack: function (e) {
|
|
var o = e.target.index;
|
|
this.otherItems[o].x = this.originPos[o].x;
|
|
this.otherItems[o].y = this.originPos[o].y;
|
|
},
|
|
onMoveEnd: function (e) {
|
|
e.target.x;
|
|
e.target.y;
|
|
if (this.cankaoItem && this.node.canTesting && 1 == this.cankaoItem.active) {
|
|
var o = cc.global.onTransitionPosition(this.rightItem.parent, this.cankaoItem.parent, e.target.getPosition());
|
|
if (this.cankaoItem.getBoundingBox().contains(o)) {
|
|
if (cc.global.levelCountOrder) {
|
|
cc.global.levelCountOrder.finshiNmu.push(this.node.name);
|
|
console.log("进这里了");
|
|
}
|
|
this.onRight();
|
|
if (!this.isshow) {
|
|
return void (this.rightItem.active = this.isshow);
|
|
}
|
|
this.rightItem.parent = this.cankaoItem;
|
|
this.rightItem.setPosition(0, 0);
|
|
} else {
|
|
if (cc.global.levelCountOrder) {
|
|
for (var t = 0; t < cc.global.levelCountOrder.finshiNmu.length; t++) {
|
|
-1 != this.node.name.indexOf(cc.global.levelCountOrder.finshiNmu[t]) && cc.global.levelCountOrder.finshiNmu.pop(this.node.name);
|
|
}
|
|
}
|
|
e.target.scale = this.originScale;
|
|
cc.global._gameManage.onChaHao();
|
|
e.target.setPosition(this.originPos.x, this.originPos.y);
|
|
}
|
|
} else {
|
|
cc.global._gameManage.onChaHao();
|
|
e.target.scale = this.originScale;
|
|
this.rightItem.setPosition(this.originPos.x, this.originPos.y);
|
|
}
|
|
},
|
|
onRight: function (e) {
|
|
setTimeout(function () {
|
|
cc.global.levelCountOrder.chengaOrder();
|
|
cc.global.levelCountOrder.jiance();
|
|
}, this.startTime);
|
|
if (cc.global.levelCountOrder.finshiNmu.length == cc.global.levelCountOrder.morenNode.length && this.eventNode_over2) {
|
|
this.eventNode_over2.switchEvent();
|
|
} else {
|
|
this.eventNode_over && this.eventNode_over.switchEvent();
|
|
}
|
|
this.rightItem.off(cc.Node.EventType.TOUCH_START, this.onMoveStart, this);
|
|
this.rightItem.off(cc.Node.EventType.TOUCH_END, this.onMoveEnd, this);
|
|
this.rightItem.off(cc.Node.EventType.TOUCH_MOVE, this.onMove, this);
|
|
}
|
|
}); |