Files
game1/assets/_script/MovePoint_pool.js
T
tothvillar e896e2ead4 init
2026-07-09 15:04:14 +08:00

103 lines
3.8 KiB
JavaScript

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: "移动完成事件节点"
},
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;
}
this.originPos1 = [];
for (var e = 0; e < this.otherItems.length; e++) {
this.otherItems[e].on(cc.Node.EventType.TOUCH_START, this.onMoveStart.bind(this));
this.otherItems[e].on(cc.Node.EventType.TOUCH_MOVE, this.onMove.bind(this));
this.otherItems[e].on(cc.Node.EventType.TOUCH_END, this.onMoveEndBack.bind(this));
this.otherItems[e].index = e;
this.originPos1.push(this.otherItems[e].getPosition());
}
},
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.originPos1[o].x;
this.otherItems[o].y = this.originPos1[o].y;
cc.global._gameManage.onChaHao();
},
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) {
cc.global.levelCount.jiance();
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);
}
});