标签:his target div convert oca self ace eve 新版
利用触摸位置判断,点击的是屏幕的左侧还是右侧,控制主角左右移动;
见代码:
InputControl:function () { var self=this; //cc.systemEvent self.node.on(cc.Node.EventType.TOUCH_START,function(event){ var target=event.getCurrentTarget(); var touches = event.getTouches(); var touchLoc = touches[0].getLocation(); var locationNode=target.convertToNodeSpace(touchLoc); if(locationNode.x< self.node.width/2){ self.MoveToLeft(); //向左边移动的函数 } else{ self.MoveToRight();//向右边移动的函数 } return true; },self.node); self.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) { }, self.node); self.node.on(cc.Node.EventType.TOUCH_END, function (event) { }, self.node); }, MoveToRight:function () { var goright=cc.moveTo(0.2,cc.p(this.node.width/2-this.borderWith,this.player.getPositionY())).easing(cc.easeCubicActionIn()); this.player.runAction(goright); }, MoveToLeft:function () { var goleft=cc.moveTo(0.2,cc.p(-(this.node.width/2-this.borderWith),this.player.getPositionY())).easing(cc.easeCubicActionIn()); this.player.runAction(goleft); },
标签:his target div convert oca self ace eve 新版
原文地址:https://www.cnblogs.com/allyh/p/9538948.html