Cocos-JS 加载Cocos Studio文件获取按钮实现

前端之家收集整理的这篇文章主要介绍了Cocos-JS 加载Cocos Studio文件获取按钮实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Cocos Studio添加按钮@H_502_2@

@H_502_2@

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) ; }}) ;
原文链接:https://www.f2er.com/cocos2dx/338159.html

猜你在找的Cocos2d-x相关文章