2012-11-13 1 views
0

내가 다음 코드를 사용하여 CCMenuItem 하위 클래스하려고 :cocos2d : CCMenuItem을 서브 클래 싱하면 많은 "removeChildByTag : child not found!"가 트리거됩니다.

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 * 버튼을 사용하고 때마다 = [GenericButton 항목 ....], CCScene에 "removeChildByTag : child not found!"가 많이 있습니다. 콘솔에 게재. 내가 뭔가 잘못하고 있는거야? 건배

답변

0

2 개월이 지난 후에 당신은 아마 이것을 알아 냈을 것입니다. 이 웹 사이트는 누군가에게 PM 방법을 제공하지 않습니까? 미안 해요. 만약 내가 부활한다면.

이 클래스에 대한 모든 코드를 포함하지는 않습니다. 그러나, 내가 봤다 뭔가 문제가 지적하고 문제의 원천이 될 수 있습니다. 클래스 메서드에서 "button"이라는 "CCMenuItemSprite"에 대한 포인터를 만들고 반환합니다. 이 클래스는 "GenericButton"클래스에 대한 포인터 여야합니다.