onLoad () {
var self=this;
self.subPos=cc.p(0,0);
self.isMoving=false;
this.nodePos=this.node.getPosition();
this.node.parent.on(cc.Node.EventType.TOUCH_START,function(event){
this.isMoving=true;
},this);
this.node.parent.on(cc.Node.EventType.TOUCH_MOVE, function(event){
var touches=event.getTouches();
//触摸刚开始的位置
var oldPos = self.node.parent.convertToNodeSpaceAR(touches[0].getStartLocation());
//触摸时不断变更的位置
var newPos = self.node.parent.convertToNodeSpaceAR(touches[0].getLocation());
self.subPos=newPos.sub(oldPos);
console.log("move");
}, this);
this.node.parent.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.parent.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
},
这是角色移动部分的代码