cocos2d-js 3.8.1
1、先加载cocostudio导出的json文件,代码如下所示:
var dong = ccs.load("res/Login.json"); //_login.setPosition(size.width/2,size.height/2); //_login.setTag(10000); this.addChild(dong.node);
var _login = ccui.helper.seekWidgetByName(dong.node,"Button_1_2_6_10");通过Tag来获取组件,代码如下所示:
var _login = ccui.helper.seekWidgetByTag(dong.node,93);
//_login.addTouchEventListener(this.btnCallback,this);_login.addTouchEventListener(this.btnCallback,this);
4、事件回调方法:
btnCallback : function(render,type){ if(type == ccui.Widget.TOUCH_ENDED){ cc.log("输出 Click Button"); } }
原文链接:https://www.f2er.com/cocos2dx/340917.html