创建新项目,目标是把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); } });

 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-10-04
  • 2021-09-04
  • 2022-12-23
  • 2021-06-30
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案