嗨,我正在尝试添加多个相同的节点并为其分配不同的名称,然后在计数超过 2 时删除其中一个。所有这些都有效,除了在按名称删除子节点并返回错误时崩溃“无效的名称”有人可以帮忙吗?我认为这有点不同,因为我使用的是 Sprite Builder 并且 cocos2d 删除了“removeChildrenByTag”
-(void)addTowers:(NSTimer *) timer
{
towerCount++;
if (_towerDown.children.count >= 2) {
[_towerUp removeChildByName:@"tower1" cleanup:YES];
towerCount = 0;
}
else
{
//Tower Up
towerUp = [CCBReader load:@"TowerUp"];
towerUp.name = [NSString stringWithFormat:@"tower%d",towerCount];
[_towerUp addChild:towerUp z:1 name:towerUp.name];
}