我正在尝试使用以下代码子类化CCMenuItem:
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
但每当我使用GenericButton * button = [GenericButton item ....]时,在CCScene中,有很多“removeChildByTag:child not found!”显示在控制台上。难道我做错了什么? 干杯
答案 0 :(得分:0)
两个月后你可能已经想到了这一点。这个网站有没有办法让PM有人?很抱歉,如果我复活和旧线程。
您没有包含此课程的所有代码。但是,我可以指出我看到的问题,这可能是你问题的根源。在您的类方法中,您正在创建并返回一个名为“button”的“CCMenuItemSprite”指针。这应该是指向“GenericButton”类的指针。