Cocosd2d-js 使用Cocos Studio生成的Json界面文件

使用Cocos Studio生成界面文件,用Js进行加载,将生成Json文件和图片素材放在res目录下,比如登陆界面的LoginScene.json文件加载如下:

        var UIroot = ccs.load(game.resources["LoginScene_json"]).node;
        UIroot.setAnchorPoint(cc.p(0.5,0.5));
        UIroot.setPosition(size.width/2,size.height/2);
        this.addChild(UIroot, 0);

        var accountEdit = ccui.helper.seekWidgetByName(UIroot, "UserInput");
        accountEdit.setPlaceHolder("Input account");
        accountEdit.addEventListener(this.textFieldEvent.bind(this),this);
        accountEdit.setName("account");
        //accountEdit.setDelegate(this);

        var passEdit = ccui.helper.seekWidgetByName(UIroot, "PassInput");
        passEdit.setPlaceHolder("Input password");
        passEdit.addEventListener(this.textFieldEvent.bind(this),this);
        passEdit.setName("password");
        //passEdit.setDelegate(this);

        var closeBtn = ccui.helper.seekWidgetByName(UIroot, "CloseBtn");
        // closeBtn.setEnabled(false);
        closeBtn.addClickEventListener(this.onTest.bind(this));
        closeBtn.setBright(true);
        closeBtn.setTouchEnabled(true);
        closeBtn.setEnabled(true);

        var loginBtn = ccui.helper.seekWidgetByName(UIroot, "LoginBtn");
        loginBtn.addClickEventListener(this.onLogin.bind(this));

        var registBtn = ccui.helper.seekWidgetByName(UIroot, "RegistBtn");
        registBtn.addClickEventListener(this.onRegister.bind(this));

        var oneKeyBtn = ccui.helper.seekWidgetByName(UIroot, "OneKeyBtn");
        oneKeyBtn.addClickEventListener(this.onSingleLogin.bind(this));

你可能感兴趣的:(JavaScript,cocos2d,界面)