Cocos2d-JS引入其他场景小实例

时间:2022-06-08 02:34:43

创建新项目,目标是把LogoNode.js场景引入app.js

新建LogoNode.js

var LogoLayer = cc.Layer.extend({
ctor:function () { this._super();
//引入图片
var startBtn=new cc.Sprite(res.start_N_png);
this.addChild(startBtn); return true;
}
});

project.json引入新资源LogoNode.js

{
"project_type": "javascript", "debugMode" : 1,
"showFPS" : true,
"frameRate" : 60,
"id" : "gameCanvas",
"renderMode" : 0,
"engineDir":"frameworks/cocos2d-html5", "modules" : ["cocos2d"], "jsList" : [
"src/resource.js",
"src/LogoNode.js",
"src/app.js"
]
}

app.js

var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();
var size=cc.winSize;
var logo=new LogoLayer();
this.addChild(logo);
logo.setPosition(size.width/2,size.height/2); return true;
}
}); var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});