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

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

Cocos Studio添加按钮


app.js

var HelloWorldLayer = cc.@H_403_12@Layer.extend({
    @H_403_12@sprite: null,    ctor: function () {
        //////////////////////////////
        // 1. super init first
        this.@H_403_12@_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.@H_403_12@winSize;
        // 加载Cocos Studio资源
        var mainscene = ccs.load(res.@H_403_12@MainScene_json);
        this.addChild(mainscene.@H_403_12@node);
        var startButton = ccui.@H_403_12@helper.seekWidgetByName(mainscene.@H_403_12@node,"Button_1");
        startButton.addTouchEventListener(this.onClick,this);

        return true;
    },    onClick: function (sender,type) {
        switch (type) {
            case ccui.@H_403_12@Widget.@H_403_12@TOUCH_BEGAN:

                break;
            case ccui.@H_403_12@Widget.@H_403_12@TOUCH_MOVED:

                break;
            case ccui.@H_403_12@Widget.@H_403_12@TOUCH_ENDED:
                console.log("startButtonOnClick");
                cc.@H_403_12@director.runScene(new GameScene);
              break;
case ccui. @H_403_12@Widget. @H_403_12@TOUCH_CANCELED: break ; } }}) ; var HelloWorldScene = cc. @H_403_12@Scene. extend({ onEnter: function () { this. @H_403_12@_super() ; var layer = new HelloWorldLayer() ; this. addChild(layer) ; }}) ;

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