我对 Objective-C 和 Cocos2d 还是很陌生,我真的不明白为什么我会在下面的代码中收到以下错误。能否请你帮忙 ?
- (NSArray *) menuItemsArray
{
NSMutableArray *array = [NSMutableArray alloc];
for (Player * player in playersArray) {
NSLog(@"creating menu item with image %@",player.imageFilename);
CCLayer *newPage = [[CCLayer alloc] init];
CCMenuItemImage *titem = [CCMenuItemImage itemFromNormalImage:player.imageFilename
selectedImage:player.imageFilename
target:self selector:@selector(playerSelected:)];
CCMenu *menu = [CCMenu menuWithItems: titem, nil];
menu.position = ccp(self.contentSize.width/2, self.contentSize.height/2);
NSLog(@"before adding item to layer");
//[titem removeFromParentWithCleanup:YES];
[newPage addChild:titem];
//[newPage release];
NSLog(@"after adding item to layer");
[array addObject:newPage];
/*
[titem release];*/
//[newPage release];
//[menu release];
}
return array;
}
我得到了错误:
2012-06-15 17:13:11.003 Killer[3222:707] *** Assertion failure in -[CCLayer addChild:z:tag:], /Users/max/Documents/workspace/Killer/Killer/libs/cocos2d/CCNode.m:388
2012-06-15 17:13:11.006 Killer[3222:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'
对不起,如果这个问题非常低级......如果你能帮助我,谢谢!:)