2013-09-14 4 views
0

removeChildByTag: ребенок не найден. Вот мой код, пожалуйста, помогите! Я довольно новый разработчик с cocos2d, поэтому я не могу понять, что вызывает Xcode, чтобы дать мне эту ошибку.removeChildByTag: child not found error

//Life System 
     CCSprite *Life3 = [CCSprite spriteWithFile:@"heart.png"]; 
     Life3.position = ccp(210,200); 
     CCSprite *Life2 = [CCSprite spriteWithFile:@"heart.png"]; 
     Life2.position = ccp(220,200); 
     CCSprite *Life1 = [CCSprite spriteWithFile:@"heart.png"]; 
     Life1.position = ccp(230,200); 
     [self addChild:Life3]; 
     [self addChild:Life2]; 
     [self addChild:Life1]; 
     if(Life == 2) { 
      [self removeChildByTag:Life3]; 
     } 
     else if(Life == 1) { 
      [self removeChild:Life2]; 
      [self removeChild:Life3]; 
     } 
     else if(Life <= 0) { 
      [self removeChild:Life1]; 
      [self removeChild:Life2]; 
      [self removeChild:Life3]; 
      [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene]]]; 
     } 

ответ

0

В условном для жизни == 2, она должна быть RemoveChild, не removeChildByTag

+0

Все еще не работает –

+0

В каком виде? Есть ли другая ошибка, такая же? Если это та же ошибка, найдите свой проект для removeChildByTag и убедитесь, что вы имеете в виду его, а не просто removeChild – Mark

+0

Он работает, он просто не обновляет, я считаю, –

0

Я разместил свой код с надлежащим образом для удаления ребенка с помощью тега.
removeChildByTag нуждается в целочисленный тег, а не объект (в вашем случае, спрайт)

CCSprite *Life3 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life3.tag = 3; 
    Life3.position = ccp(210,200); 

    CCSprite *Life2 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life2.tag = 2; 
    Life2.position = ccp(220,200); 

    CCSprite *Life1 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life1.tag = 1; 
    Life1.position = ccp(230,200); 

    [self addChild:Life3]; 
    [self addChild:Life2]; 
    [self addChild:Life1]; 

    if(Life == 2) { 
     [self removeChildByTag:3]; 
    } 
    else if(Life == 1) { 
     [self removeChild:2]; 
     [self removeChild:1]; 
    } 
    else if(Life <= 0) { 
     [self removeChild:1]; 
     [self removeChild:2]; 
     [self removeChild:3]; 
     [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene]]]; 
    } 
+0

Еще не повезло :( –

0

Попробуйте заменить все [само RemoveChild:] или [само removeChildbyTag:] с

[себе RemoveChild: Life1 clean: YES]

Если это также не сработает, я предлагаю вам просто [self addChild:], когда вам нужно. Не добавляйте все три Lifes в качестве детей в начале. Таким образом, код станет следующим:

CCSprite *Life3 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life3.position = ccp(210,200); 
    CCSprite *Life2 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life2.position = ccp(220,200); 
    CCSprite *Life1 = [CCSprite spriteWithFile:@"heart.png"]; 
    Life1.position = ccp(230,200); 

    if(Life == 2) { 
     [self addChild:Life2]; 
     [self addChild:Life1]; 
    } 
    else if(Life == 1) { 
     [self addChild:Life1]; 
    } 
    else if(Life <= 0) { 
     [self addChild:Life3]; 
     [self addChild:Life2]; 
     [self addChild:Life1]; 
     [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene]]]; 
    }