开发者

problem: menu does not show in cocos2d layer

开发者 https://www.devze.com 2023-02-10 20:38 出处:网络
I am trying to add menu to a layer in cocos2d bu开发者_如何学运维t it just does not appear. Here\'s the code which is written in init method of a layer

I am trying to add menu to a layer in cocos2d bu开发者_如何学运维t it just does not appear. Here's the code which is written in init method of a layer

CCMenuItem *aButton = [CCMenuItemImage itemFromNormalImage:@"btnImg.png" selectedImage:@"btnImgSel.png" target:self selector:@selector(buttonPressed:)];
aButton.position = ccp(60.0,30.0);
CCMenu *aMenu = [CCMenu menuWithItems:aButton, nil];
aMenu.position = ccp(500.0,20);
[self addChild:aMenu];

Nothing is overlapping the position i specified for menu. Is anything wrong in the code?


Try like these:-

CCLayer *menuLayer1 = [[[CCLayer alloc] init]autorelease];
        [self addChild:menuLayer1];

CCMenuItemImage *startButton1 = [CCMenuItemImage
itemFromNormalImage:@"Play.png"
selectedImage:@"Play.png"                                             
 target:self
selector:@selector(Play:)];
 CCMenu *menu1 = [CCMenu menuWithItems: startButton1,nil];
    menu1.position = ccp(157,157 );
        [menu1 alignItemsVertically ];
        [menuLayer1 addChild: menu1];


For those who are facing an irritating situation where the code is right but menu items are not showing then check the image file. I was using .png images and they were refusing to be displayed. There was something internally wrong with the file, so I replaced that file and it solved the problem :)


Is the iPad your target platform? If so the "menu" should appear at the bottom of the screen. To display the Menu on iPhone adjust the "a.Menu.position" to anything lower than 480 in the first attribute of ccp

0

精彩评论

暂无评论...
验证码 换一张
取 消