This is the function I am using in my code:
-(id) initFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite
selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite
activeSprite:(CCNode<CCRGBAProtocol>*)activeSprite
disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite
name:(NSString*)name
target:(id)target selector:(SEL)selector
{ if (( self = [super initFro开发者_C百科mNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:disabledSprite target:target selector:selector])) { self.activeImage = activeSprite; self.name = name;
// TODO, create an addSpriteFrameByName extension
CCSpriteFrameCache* fcache = [CCSpriteFrameCache sharedSpriteFrameCache];
NSString* glowName = @"frames-glow.png";
if([fcache spriteFrameByName: glowName]) {
} else {
CCTexture2D* glowTex = [[CCTexture2D alloc] initWithImage: [UIImage imageNamed:glowName]];
CCSpriteFrame* spriteFrame = [[CCSpriteFrame alloc] initWithTexture:glowTex
rect:CGRectMake(0,0,glowTex.pixelsWide,glowTex.pixelsHigh)];
//offset: ccp(0,0)];
[fcache addSpriteFrame:spriteFrame name:glowName];
[spriteFrame release];
[glowTex release];
}
self.glow = [CCSprite spriteWithSpriteFrameName:glowName];
self.showGlow = true;
}
return self;
}
It's building fine but crashes in simulator with the following:
2010-12-24 23:22:48.417 PanelsExample[8967:207] * Assertion failure in -[NMPanelMenuItem addChild:z:tag:], /Users/aeshverma/Downloads/jashmenn-shapes-panels-bcf4e74/cocos2d/CCNode.m:360 2010-12-24 23:22:48.430 PanelsExample[8967:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'
please help me out.
Thanks
not sure, but it appears as though you could be adding the texture multiple times to the CCSpriteFrameCache. The best way to identify this problem is to execute the game with debugging, and when it "breaks" ... launch the Debugger window, and step backwards to where your code is and identify the line of code that is causing the problem - then work from there.
This also seems like an improper use of a custom class as well, but that's a discussion for another topic.
精彩评论