两个脚本的相互加载

来源:互联网 发布:c语言区间内素数 编辑:程序博客网 时间:2024/05/01 21:15

今天用了一天的时间实现两个界面的交换,实则是两个脚本的相互加载,通过特定的点击事件完成!

第一个脚本加载第二部分

currentTotal = 4;var HelloWorldLayer = cc.Layer.extend({    _mainUI:null,    _a:null,    _number:4,    _resultLab:null,    MAX:6,    MIN:3,    ctor:function () {        this._super();        this._init();    },    //初始化    _init:function(){        this._mainUI = ccs.load(res.tite_json).node;        this.addChild(this._mainUI);        this._playGame();    },    //点击游戏进入    _playGame:function(){        this._a = this._getWidgetByName(this._mainUI, "playBtn" );        this._a.addTouchEventListener(this._inputHandler.bind(this), this._mainUI);        this._getWidgetByName(this._mainUI, "leftBtn").addTouchEventListener(this._leftBtn.bind(this),this._mainUI);        this._getWidgetByName(this._mainUI, "rigthBtn").addTouchEventListener(this._regtBtn.bind(this),this._mainUI);        this._resultLab = this._getWidgetByName(this._mainUI,"Label_5");    },    _inputHandler:function(sender,type) {        if (type == ccui.Widget.TOUCH_ENDED) {            if (sender. name == "playBtn")this._changeScene();        }    },    _changeScene:function(){        var scene =new cc.TransitionRotoZoom(1,new GameSence());        cc.director.runScene(scene);    },    //函数封装    _getWidgetByName:function(par,name){        return ccui.helper.seekWidgetByName(par,name);    },var HelloWorldScene = cc.Scene.extend({    onEnter:function () {        this._super();        var layer = new HelloWorldLayer();        this.addChild(layer);    }});
第二脚本加载第一脚本部分
var GameMainLayer = cc.Layer.extend({    _a:null,    ctor:function () {        this._super();        this._init();    },    _init:function(){        this._mainUI = ccs.load(res.game_json).node;        this.addChild(this._mainUI);        this._backMenu()    },    //返回菜单    _backMenu:function() {        this._a = this._getWidgetByName(this._mainUI, "backBtn" );        this._a.addTouchEventListener(this._inputHandler.bind(this), this._mainUI)    },    //回调事件    _inputHandler:function(sender,type){        if (type == ccui.Widget.TOUCH_ENDED) {            if (sender.name == "backBtn")this._changeScene();        }    },    _changeScene:function(){        var scene =new cc.TransitionFadeTR(1,new HelloWorldLayer());        cc.director.runScene(scene);           //加载游戏内界面    },    //函数封装    _getWidgetByName:function(par,name){        return ccui.helper.seekWidgetByName(par,name);    }});var GameSence = cc.Scene.extend({    onEnter:function () {        this._super();        this.addChild(new GameMainLayer());    }});
便实现了两网页的神奇转换

0 0
原创粉丝点击