Cocos2d-JS替换初始化场景

Cocos2d-js工程默认启动入口为app.js,准备修改为另外一个入口文件如:GameScene.js

var GameLayer = cc.Layer.extend({
    ctor:function () {
        //////////////////////////////
        // 1. super init first
        this._super();

    //你的代码..

        return true;
    }
});

var GameScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new GameLayer();
        this.addChild(layer);
    }
});

修改main.js,将new HelloWorldScene()改为new GameScene()

cc.game.onStart = function(){
    cc.view.adjustViewPort(true);
    cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.SHOW_ALL);
    cc.view.resizeWithBrowserSize(true);
    //load resources
    cc.LoaderScene.preload(g_resources, function () {
        cc.director.runScene(new GameScene());
    }, this);
};
cc.game.run();

project.json中加入文件资源

{
    "project_type": "javascript",

    "debugMode" : 1,
    "showFPS" : true,
    "frameRate" : 60,
    "id" : "gameCanvas",
    "renderMode" : 0,
    "engineDir":"frameworks/cocos2d-html5",

    "modules" : ["cocos2d"],

    "jsList" : [
        "src/resource.js",
         "src/GameScene.js",
        "src/app.js"
    ]
}

 

posted @ 2016-01-18 16:42  tinyphp  Views(592)  Comments(0Edit  收藏  举报