(三)、“仙剑出鞘”---剑阵盘的控制

主要代码

1
2
3
4
5
6
7
8
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove , this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        // this.mEnableTouch = true;
        console.log("mEnableTouch on");
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
     
    onTouchMove (event) {
var touches = event.getTouches();
var touchLoc = touches[0].getLocation();
// this.mHookMoveToPos = this.node.parent.convertToNodeSpaceAR(touchLoc);
// console.log('touchLoc : ', touchLoc);

let toX:Number = touchLoc.x - Number(this.preX)
var toY:Number = touchLoc.y - Number(this.preY)
this.preX = touchLoc.x
this.preY = touchLoc.y
console.log('touchLoc.x',touchLoc.x)
console.log('preX',this.preX)
console.log('touchLoc.y',touchLoc.y)
console.log('preY',this.preY)
if( toX > 0 ) {
console.log(" > 0")
this.mPan.angle +=2
}
if( toX < 0 ) {
console.log(" < 0")
this.mPan.angle -=2
}

    }

主要涉及的cocos函数

1、event.getTouches()

获取触碰点

2、cc.Node.EventType.TOUCH_MOVE

事件类型