Cocos-JS 加载Cocos Studio文件获取按钮实现
发布时间:2020-12-14 17:29:19 所属栏目:百科 来源:网络整理
导读:Cocos Studio中添加按钮 app.js var HelloWorldLayer = cc. Layer . extend ({ sprite : null , ctor : function () { ////////////////////////////// // 1. super init first this . _super () ; ///////////////////////////// // 2. add a menu item wit
Cocos Studio中添加按钮 app.js var HelloWorldLayer = cc.Layer.extend({ sprite: null, ctor: function () { ////////////////////////////// // 1. super init first this._super(); ///////////////////////////// // 2. add a menu item with "X" image,which is clicked to quit the program // you may modify it. // ask the window size var size = cc.winSize; // 加载Cocos Studio资源 var mainscene = ccs.load(res.MainScene_json); this.addChild(mainscene.node); var startButton = ccui.helper.seekWidgetByName(mainscene.node,"Button_1"); startButton.addTouchEventListener(this.onClick,this); return true; }, onClick: function (sender,type) { switch (type) { case ccui.Widget.TOUCH_BEGAN: break; case ccui.Widget.TOUCH_MOVED: break; case ccui.Widget.TOUCH_ENDED: console.log("startButtonOnClick"); cc.director.runScene(new GameScene); break;case ccui. Widget. TOUCH_CANCELED: break ; } }}) ; var HelloWorldScene = cc. Scene. extend({ onEnter: function () { this. _super() ; var layer = new HelloWorldLayer() ; this. addChild(layer) ; }}) ; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |