Ottenere il livello non è definito
-
21-12-2019 - |
Domanda
Sto cercando di creare un livello di menu, ma sto ottenendo questo errore sulla console Chrome:
MenuLayer is not defined
.
Ma questo è il mio menu.js che definisce il menuleyer:
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;
};
.
E questo è il mio codice in cui mi riferisco a Menu.js e alla scena di avviamento, rispettivamente:
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);
. Soluzione
L'unica risposta immagino è che tu abbia bisogno di vuota le cache. (Chrome) Apri "Strumenti per sviluppatori" -> "Opzioni" -> "Disabilita cache" e ricarica la pagina senza chiusura strumenti di dev
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow