2011-12-27 6 views
1

1パーセントを表す複数のイメージを整列させて、独自のヘルスインジケータを作成したいと考えています。基本的に、現在の健康状態に基づいて、私は必要に応じて1パーセントのパーツを整列させます。しかし、それらを削除することは問題であるようです。独自のヘルス・インジケーターに関する問題。 Cocos2d

-(void)updateHealthIndicator:(ccTime)delta{ 

    //getting health and healthReduction (removed for better readability). This part does not affect the functioning of the loop... 


    if(health-healthReduction > 0){ 
     NSLog(@"updatehealthindicator called ! health = %d ", health); 
     health -= healthReduction; 

     [self removeChildByTag:1000 cleanup:YES]; 
     for (int i = health; i>0; i--){ 
      onePercent = [CCSprite spriteWithFile:@"onepercentofhi.png"]; 
      onePercent.anchorPoint = ccp(0,0); 
      onePercent.position = ccp(880+(-onePercent.contentSize.width) * i,712); 
      [self addChild:onePercent z:2 tag:1000]; 

     } 



} 

ヘルスインジケータが現れ、それだけで最初の「1パーセント」の部分を削除しているようです。タグ1000のすべてのスプライトがこの[self removeChildByTag:1000 cleanup:YES];の影響を受けていますか?

答えて

1

特定のタグを持つ1つのビューのみが削除されます。

しかし、あなたは注意

-(void) removeChildrenByTag:(int)aTag cleanup:(BOOL)cleanup 
{ 
    NSAssert(aTag != kCocosNodeTagInvalid, @"Invalid tag"); 
    int w=[children count]-1; 
    while(w>=0){ 
     CocosNode *node=[children objectAtIndex:w]; 
     if(node.tag == aTag){ 
      [self detachChild:node cleanup:cleanup]; 
     } 
     w--; 
    } 
} 

すべての子を削除するには、次のコードでCCNodeを拡張できます。これはCocos2Dに統合するproposed solutionですが、まだそれを行っていません。

+0

コードが動作します!本当にありがとう !!! –

関連する問題