0

Hi I'm trying to add multiple nodes that are the same and assign them different names and then remove one of them when the count gets above 2. All of this works except it is crashing when removing the child by name and returning the error "Invalid Name" can anyone help? I think it is a little different because I am using Sprite Builder and also cocos2d removed "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];
        }
James Webster
  • 31,873
  • 11
  • 70
  • 114
Inovize
  • 233
  • 3
  • 13

1 Answers1

0

There's a silly bug in the Cocos2d v3 code. Upgrade to the latest version or change

NSAssert( !name, @"Invalid name");

to

NSAssert( name, @"Invalid name");

in removeChildByName

Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59