cc.Class({ extends: cc.Component, properties: { rightItem: cc.Node, otherItems: { type: cc.Node, default: [] }, 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) { var o = cc.global.onTransitionPosition(this.rightItem.parent, this.cankaoItem.parent, e.target.getPosition()); if (this.cankaoItem.getBoundingBox().contains(o)) { if (this.node.parent.getComponent("levelCount")) { this.node.parent.getComponent("levelCount").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 (this.node.parent.getComponent("levelCount")) { for (var t = 0; t < this.node.parent.getComponent("levelCount").finshiNmu.length; t++) { -1 != this.node.name.indexOf(this.node.parent.getComponent("levelCount").finshiNmu[t]) && this.node.parent.getComponent("levelCount").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) { if (1 == cc.global.levelCount.finshiNmu.length) { this.eventNode_over && this.eventNode_over.switchEvent(); } else { this.eventNode_over2 && this.eventNode_over2.switchEvent(); } cc.global.levelCount.jiance(); 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); } });