前端之家收集整理的这篇文章主要介绍了
cocos-js 3.8 控件触摸事件处理,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
var HelloWorldLayer = cc.Layer.extend({
sprite:@H_403_4@null,_startBtn:@H_403_4@null,ctor:function () {
this._super();
var size = cc.winSize;
var mainscene = ccs.load("res/Scene.json");
this.addChild(mainscene.node);
_startBtn = ccui.helper.seekWidgetByName(mainscene.node,"Button_1");
_startBtn.addTouchEventListener(this.touchEvent,this);
touchEvent:function(sender,type){
switch(type) {
case ccui.Widget.TOUCH_BEGAN:
return @H_403_4@true;
case ccui.Widget.TOUCH_MOVED:
break;
case ccui.Widget.TOUCH_ENDED:
if(sender == _startBtn)
cc.director.end();
break;
}
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
原文链接:https://www.f2er.com/cocos2dx/341261.html