0

In cocos2d-iphone, I would like to use a sprite for the menu button item and I'd like to place a label underneath it describing the button.

However, I am not sure how to do this.

If I attempt to make more buttons/labels and then use

[menu alignItemsHorizontallyWithPadding:1.5f];

The position of the items is wrong.

Anyway, here is my code;

// Button
CCSprite *panel = [CCSprite spriteWithFile:@"panel.png"];        

// Menu
CCMenu *menu = [CCMenu menuWithItems:nil];


CCLabelBMFont *lblFont = [CCLabelBMFont labelWithString:@"Some text" fntFile:@"arial16.fnt"];

CCMenuItemLabel *mnuLabel = [CCMenuItemLabel itemWithLabel:lblFont];    

CCMenuItemSprite *mnuSprite = [CCMenuItemSprite itemFromNormalSprite:panel selectedSprite:nil disabledSprite:nil target:nil selector:nil];

[menu addChild:mnuSprite];
[menu addChild:mnuLabel];
[menu setPosition:ccp(winSize.width/2, winSize.height/2)];

[self addChild:menu z:1];
zardon
  • 2,910
  • 6
  • 37
  • 58
  • The reason why labels are meant to be under each avatar is because the label is the name of each character/avatar. – zardon May 15 '12 at 06:28

1 Answers1

2

Are you sure, you need label UNDERNEATH your sprite? If I understand right, you can just create CCMenuItemSprite instance, then add label to it as a child. smth like:

CCMenuItemSprite *mnuSprite = [CCMenuItemSprite itemFromNormalSprite:panel selectedSprite:nil disabledSprite:nil target:nil selector:nil];
CCLabelBMFont *lblFont = [CCLabelBMFont labelWithString:@"Some text" fntFile:@"arial16.fnt"];

[lblFont setAnchorPoint: ccp(0.f, 0.f)];
[mnuSprite addChild: lblFont];
Morion
  • 10,495
  • 1
  • 24
  • 33
  • Yes, I have a series of avatars and I need to put the character's name under each avatar. Your answer is accepted. – zardon May 06 '12 at 08:39