cocosCreator自带的button组件是一次点击事件,并没有长按的回调。
我们要实现按钮长按,可以用 TOUCH_START 和 TOUCH_END,代码如下:
……
onLoad () {
this.baffle = cc.find("UI_ROOT/baffle").getComponent("baffle")
//触摸开始
this.node.on(cc.Node.EventType.TOUCH_START,function(event){
this.baffle.isMoveRight = true;
},this);
this.node.on(cc.Node.EventType.TOUCH_END,function(event){
this.baffle.isMoveRight = false;
},this)
},
……
这样一来,按钮按下去的时候,this.baffle.isMoveRight = true,松开则为false。