0

I am trying to subclass a CCMenuItem using the following code:

GenericButton.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface GenericButton : CCMenuItemSprite {

}
+(id) itemwithTitle:(NSString*)title withBGColor: (ccColor3B) bgColor andFGColor:(ccColor3B)fgColor;
@end

GenericButton.m

#import "GenericButton.h"
#import "HelpfulClasses.h"

@implementation GenericButton

+(id) itemwithTitle:(NSString*)title withBGColor: (ccColor3B) bgColor andFGColor:(ccColor3B)fgColor{

CCSprite*genericButtonBG = [CCSprite spriteWithSpriteFrameName:@"genericButtonBG.png"];
genericButtonBG.color=bgColor;

CCSprite*genericButtonBGPressed = [CCSprite spriteWithSpriteFrameName:@"genericButtonBGPressed.png"];
genericButtonBGPressed.color=bgColor;

CCMenuItemSprite*button = [CCMenuItemSprite itemWithNormalSprite:genericButtonBG selectedSprite:genericButtonBGPressed];

CCSprite*fgButton = [CCSprite spriteWithSpriteFrameName:@"genericButton.png"];
fgButton.color=fgColor;
[button addNodeInMiddleOfParent:fgButton];

CCLabelBMFont *buttonTitle = [CCLabelBMFont labelWithString:title fntFile:@"font.fnt"];
if ([title length]>7) {
buttonTitle.scale=0.85;
}
buttonTitle.color=ccYELLOW;
[fgButton addNodeInMiddleOfParent:buttonTitle];

return button;

}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)

// don't forget to call "super dealloc"
[super dealloc];
}

@end

But whenever I am using GenericButton*button = [GenericButton item....], in a CCScene, there is a lot of"removeChildByTag: child not found!" showing on the console. Am I doing something wrong? Cheers

Cyril Gaillard
  • 909
  • 9
  • 28

1 Answers1

0

After two months you've probably figured this out yourself. Doesn't this website have a way to PM somebody? So sorry if I resurrect and old thread.

You are not including all your code for this class. However, I can point out something I saw that is an issue and could possibly be the source of your problem. In your class method you are creating and returning a pointer to "CCMenuItemSprite" called "button". This should be a pointer to your class "GenericButton".

James
  • 1