Hi all,
I am trying to create a subclass of CCMenuItem to combine a CCMenuItemImage with 2 CCMenuItemLabels. Everything seems to be working as expected except that the touchable area for the menu item is not aligned with the image or labels. Here is a picture of what I am talking about:

I have the sprite debug on for the rectangles around the image and the labels. The white box that is offset is the calculated contentSize of the menu item from the subclass. Here is the code:
+ (id)itemFromNormalImage:(NSString *)imagePath1 selectedImage:(NSString *)imagePath2 withString:(NSString *)aString atOffset:(NSNumber *)anOffset withShadow:(BOOL)aShadow atShadowPosition:(CGPoint)shadowPosition target:(id)aTarget selector:(SEL)aSelector {
return [[[self alloc] initFromNormalImage:imagePath1 selectedImage:imagePath2 withString:aString atOffset:anOffset withShadow:aShadow atShadowPosition:shadowPosition target:aTarget selector:aSelector] autorelease];
}
- (id)initFromNormalImage:(NSString *)imagePath1 selectedImage:(NSString *)imagePath2 withString:(NSString *)aString atOffset:(NSNumber *)anOffset withShadow:(BOOL)aShadow atShadowPosition:(CGPoint)shadowPosition target:(id)aTarget selector:(SEL)aSelector {
self = [super initWithTarget:aTarget selector:aSelector];
if (self != nil) {
// create the menuItemImage
self.menuItemImage = [CCMenuItemImage itemFromNormalImage:imagePath1 selectedImage:imagePath2 target:aTarget selector:aSelector];
// create the menuItemLabel
self.menuItemLabel = [CCMenuItemLabel itemWithLabel:[CCLabel labelWithString:aString fontName:@"Mufferaw_Bold" fontSize:24] target:aTarget selector:aSelector];
// set the color of the menuItemLabel to white
[self.menuItemLabel setColor:ccc3(255,255,255)];
// add the children
[self addChild:self.menuItemImage z:0];
[self addChild:self.menuItemLabel z:0];
// set the position of the label padding with respect to the normal image
[self.menuItemLabel setPosition:ccp(self.menuItemImage.position.x + [self.menuItemImage boundingBox].size.width + [anOffset intValue], self.menuItemImage.position.y)];
// create the shadow
if (aShadow) {
// find the center of the label so that position will be relative via an offset
CGPoint center = ccp([menuItemLabel contentSize].width/2, [menuItemLabel contentSize].height/2);
// set the shadow text to be the same as the label
self.menuItemShadowLabel = [CCLabel labelWithString:aString fontName:@"Mufferaw_Bold" fontSize:24];
// set the shadow text to black
[self.menuItemShadowLabel setColor:ccc3(0,0,0)];
// set the position of the shadow relative to the menuItemLabel
[self.menuItemShadowLabel setPosition:ccpAdd(center, shadowPosition)];
// add the shadow as a child to the menuItemLabel
[self.menuItemLabel addChild:menuItemShadowLabel z:-1];
}
// calculate the content size of the menu item
[self calculateContentSize];
}
return self;
}
- (void)setImageScale:(CGFloat)aScale {
// scale the image
[self.menuItemImage setScale:aScale];
// re-calculate the content size
[self calculateContentSize];
}
- (void)calculateContentSize {
// set the contentSize of the entire menu item
CGFloat width = 0, height = 0;
for (CCNode *child in self.children) {
width += [child boundingBox].size.width;
CGFloat tempHeight = [child boundingBox].size.height;
if (tempHeight > height) {
height = tempHeight;
}
}
CGSize itemSize = CGSizeMake(width, height);
[self setContentSize:itemSize];
}
Then in my scene I create a menu and add this item and then use the alignItemsVertically method. The only way to move to the next scene is to touch/click within that bigger offset rectangle.
Does anybody see what I need to do to put the image and the labels within the contentsize rectangle? When I try to position the menu item subclass, all move together (as expected). I guess I can try to move each item individually in the init method, but I'm wondering why this is happening in the first place and what I am missing.
Thanks