var SysMenu = cc.Layer.extend({
_ship:null,
init:function () {
var bRet = false;
if (this._super) {
winSize = cc.Director.sharedDirector().getWinSize();
var sp = cc.Sprite.spriteWithFile(s_loading);
sp.setAnchorPoint(cc.PointZero());
this.addChild(sp, 0, 1);
this.setTag(“SysMenuTag”);
var newGameNormal = cc.Sprite.spriteWithFile(“Resources/f1.png”);
var newGameSelected = cc.Sprite.spriteWithFile(“Resources/f2.png”);
var newGameDisabled = cc.Sprite.spriteWithFile(“Resources/f2.png”);
var newGame = cc.MenuItemSprite.itemFromNormalSprite(newGameNormal, newGameSelected, newGameDisabled, this, function(){
})
newGame.setScale(2, 2);
var menu = cc.Menu.menuWithItem(newGame);
menu.alignItemsVerticallyWithPadding(10);
this.addChild(menu, 1, 2);
menu.setPosition(cc.ccp(winSize.width / 2, winSize.height / 2 - 80));
bRet = true;
}
return bRet;
}
});
What’s the problem?
var SysMenu = cc.Layer.extend({
_ship:null,
ctor:function(){ // I added the ctor. However, you can just construct it and then call obj.init() without ctor.
this._super();
this.init();
},
init:function () {
var bRet = false;
if (this._super()) { // this.super(), to call the super function
winSize = cc.Director.sharedDirector().getWinSize();
var sp = cc.Sprite.spriteWithFile("Resources/HelloWorld.png");
sp.setAnchorPoint(cc.PointZero());
this.addChild(sp, 0, 1);
//this.setTag("SysMenuTag"); //Parameter type should be int.
var newGameNormal = cc.Sprite.spriteWithFile("Resources/f1.png");
var newGameSelected = cc.Sprite.spriteWithFile("Resources/f2.png");
var newGameDisabled = cc.Sprite.spriteWithFile("Resources/f2.png");
var newGame = cc.MenuItemSprite.itemFromNormalSprite(newGameNormal, newGameSelected, newGameDisabled, this, function(){
});
newGame.setScale(2, 2);
var menu = cc.Menu.menuWithItem(newGame);
menu.alignItemsVerticallyWithPadding(10);
this.addChild(menu, 1, 2);
menu.setPosition(cc.ccp(winSize.width / 2, winSize.height / 2 - 80));
bRet = true;
}
return bRet;
}
});
I have tested it in HelloWorld, and it works well. Try it by yourself.