Example of CCMenu

While developing games you need to create Menu. Cocos2d's CCMenu makes your life easier. 

You can have your own custom fancy image text indicating menu items using CCMenu.

Features and Limitation:
  • You can add MenuItem objects in runtime using addChild:
  • But the only accepted children are MenuItem objects

 //Creating the three menu items.
 //You can use different images for selected view & normal view.
 //On clicking menu will show selectedImage

 CCMenuItemImage *run = [CCMenuItemImage

 CCMenuItemImage *fire = [CCMenuItemImage

 CCMenuItemImage *jump = [CCMenuItemImage

 //Adding menu items to the CCMenu. Don't forget to include 'nil'
 CCMenu *selectMenu= [CCMenu menuWithItems:run, fire, jump, nil];
 //Aligning & Adding CCMenu child to the scene
 [selectMenu alignItemsVertically];
 [self addChild:selectMenu];

 //Different functions on below get called according to the menu item clicked.
 - (void)runAction:(id)sender
 [[CCDirector sharedDirector] replaceScene:[runningScene node]];

 - (void)fireAction:(id)sender
 [[Director sharedDirector] replaceScene:[fireScene node]];

 - (void)jumpAction:(id)sender
 [[Director sharedDirector] replaceScene:[jumpingScene node]];

No comments:

Post a Comment