How to create a menu in Cocos2d?
I need to know how to make a simple menu with 5 buttons and have them b开发者_开发知识库e on the right side of the screen in cocos2d. Do I create the menu in the -(id)init ? Any help is appreciated. Thanks!
You can use the following code to create Menu
CCMenuItemImage *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"menu.png" selectedImage:@"menu1.png"
target:self selector:@selector(onClick:)];
CCMenu *menu = [CCMenu menuWithItems:menuItem1,nil];
menu.position = ccp(320,480);
[self addChild:menu z:100];
Hope this helps.....
Do I create the menu in the -(id)init ?
Yes, create the menu in the -(id)init of CCScene subclass or CCLayer subclass as the following tutorials. It is prefer to attach the menu into CCLayer because you can adjust the position of the menu at once by setting the position of the layer.
- How To Create Buttons in Cocos2D: Simple, Radio, and Toggle
- Cocos2d Menu Tutorial
精彩评论