0

我正在尝试创建一个菜单层,但在 Chrome 控制台上出现此错误:

MenuLayer is not defined

但这是我的 menu.js,它定义了 MenuLayer:

var MenuLayer = cc.LayerColor.extend({
    ctor : function(){
        //1. call super class's ctor function
        this._super();

        cc.associateWithNative( this, cc.LayerColor );

    },
    onEnter:function () {
        this._super();

        //2. get the singleton director
        var director = cc.Director.getInstance();
        //3. get the screen size of your game canvas
        var winsize = director.getWinSize();
        //4. calculate the center point
        var centerpos = cc.p(winsize.width / 2, winsize.height / 2);

        //5. create a background image and set it's position at the center of the screen
        //var spritebg = cc.Sprite.create(s_HelloBG);
        //spritebg.setPosition(centerpos);
        //this.addChild(spritebg);

        //6.create a menu and assign onPlay event callback to it
        cc.MenuItemFont.setFontSize(60);
        var menuItemPlay= cc.MenuItemSprite.create(
            cc.Sprite.create(s_start_n),
            cc.Sprite.create(s_start_s),
            this.onPlay, this);
        var menu = cc.Menu.create(menuItemPlay);
        menu.setPosition(centerpos);
        this.addChild(menu);
    },

    //this is the callback when the menu is clicked
    onPlay : function(){
        cc.log("==onplay clicked");
        var director = cc.Director.getInstance();
        director.replaceScene(new MainLayer());
    }
});

MenuLayer.create = function () {
    var sg = new MenuLayer();
    if (sg ) {
        return sg;
    }
    return null;
};

MenuLayer.scene = function () {
    var scene = cc.Scene.create();
    var layer = MenuLayer.create();
    scene.addChild(layer);
    return scene;
};

这是我的代码,我分别引用 menu.js 和 starter Scene:

    engineDir:'./Platform/HTML5/cocos2d/',
    appFiles:[
        './Src/resource.js',
        './Src/MainLayer.js',
        './Src/GameOver.js',
        './Src/main.js',
        './Src/menu.js'
    ]

var myApp = new cocos2dApp(MenuLayer.scene);
4

1 回答 1

3

我猜唯一的答案是你需要清空缓存。(Chrome)打开“开发者工具”->“选项”->“禁用缓存”并重新加载页面而不关闭开发工具

于 2014-07-29T13:58:40.463 回答