let moveGears = this.moveGears
let len = moveGears.length
if (len <= 0) {
// console.error("没有可拖动的齿轮");
return
}
let dragArea = this.dragArea
let y = dragArea.y
let setNextGearPosLeft = (preGear, index) => {
let nextIndex = index - 1
if (nextIndex < 0) {
return
}
let nextGear = moveGears[nextIndex]
let nextGearCmpt: Gear = nextGear.getComponent(Gear) as Gear
let prevGearCmpt: Gear = preGear.getComponent(Gear) as Gear
nextGear.on(cc.Node.EventType.TOUCH_START, this.onGearTouchStart, this);
nextGear.on(cc.Node.EventType.TOUCH_MOVE, this.onGearTouchMove, this);
nextGear.on(cc.Node.EventType.TOUCH_END, this.onGearTouchEnd, this);
nextGear.x = preGear.x - prevGearCmpt.gearRadius - nextGearCmpt.gearRadius - GEAR_GAP
nextGear.y = y
setNextGearPosLeft(nextGear, nextIndex)
}
let setNextGearPosRight = (preGear, index) => {
let nextIndex = index + 1
if (nextIndex > len - 1) {
return
}
let nextGear = moveGears[nextIndex]
let nextGearCmpt: Gear = nextGear.getComponent(Gear) as Gear
let prevGearCmpt: Gear = preGear.getComponent(Gear) as Gear
nextGear.on(cc.Node.EventType.TOUCH_START, this.onGearTouchStart, this);
nextGear.on(cc.Node.EventType.TOUCH_MOVE, this.onGearTouchMove, this);
nextGear.on(cc.Node.EventType.TOUCH_END, this.onGearTouchEnd, this);
nextGear.x = preGear.x + prevGearCmpt.gearRadius + nextGearCmpt.gearRadius + GEAR_GAP
nextGear.y = y
setNextGearPosRight(nextGear, nextIndex)
}
let midIndex = Math.ceil(len / 2)
let midGear = moveGears[midIndex]
let midGearParent = midGear.parent
let midGearCmpt: Gear = midGear.getComponent(Gear) as Gear
let midGearShadowCmpt: GearShadow = midGearParent.children[0].getComponent(GearShadow)
midGearCmpt.gearShadow = midGearShadowCmpt
midGearShadowCmpt.gear = midGearCmpt
midGear.on(cc.Node.EventType.TOUCH_START, this.onGearTouchStart, this);
midGear.on(cc.Node.EventType.TOUCH_MOVE, this.onGearTouchMove, this);
midGear.on(cc.Node.EventType.TOUCH_END, this.onGearTouchEnd, this);
if (len % 2) {
let radius = midGearCmpt.gearRadius
midGear.x = radius + GEAR_GAP / 2 + dragArea.x
midGear.y = y
} else {
midGear.x = 0 + dragArea.x
midGear.y = y
}
setNextGearPosLeft(midGear, midIndex)
setNextGearPosRight(midGear, midIndex)