views:

184

answers:

2

Hey Guys,

I would like to create a menu item from an image with some text on it. Image is a button and I have to write the name of the player on the button, so I presume I have to use both MenuItemImage and MenuItemFont.

Maybe I can create an AtlasSprite using both image and text on it and then us MenuItemAtlasSprite object? If so how can I create that composite image ?

What is the recommended way to achieve this piece of functionality ?

Thanks Jugs

A: 

Any reason you can't just use UIButton? I am using Cocos2D, but realized that plain old UIButton was good enough for my needs.

Here's how I added the button to my Cocos2D layer:

  UIView *myView = [[Director sharedDirector] openGLView];

  UIButton *menuButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
  [menuButton setTitle: @"Menu" forState: UIControlStateNormal];
  menuButton.frame = CGRectMake(BUTTON_X(0), BOTTOM_BUTTON_ROW_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
  [menuButton addTarget: self action: @selector(menuButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
  [myView addSubview: menuButton];
  [myView bringSubviewToFront: menuButton];
Chris Garrett
A: 

Hey Chris,

You are adding directly to the UIView and not to the Layer. I use several Layers in a Scene and switch them around, so this wont work for me unless I hide the buttons based on the Layer visible.

I finally ended up putting a label on top of the MenuItemImage. I thought of sub-classing MenuItemImage however Cocos2d has a bug where it wont draw all the subviews.

Cheers

Jugs