首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自己的健康指标问题。Cocos2d

自己的健康指标问题。Cocos2d
EN

Stack Overflow用户
提问于 2011-12-28 03:25:36
回答 1查看 112关注 0票数 1

我想通过对齐代表百分之一的多个图像来创建我自己的健康指标。因此,基本上,基于当前的健康状况,我会根据需要对齐所有百分之一的部分。然而,删除它们似乎是一个问题。

代码语言:javascript
复制
-(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];

        }



}

健康指示器出现了,但它似乎只删除了第一个“百分之一”部分。是否所有标记为1000的精灵都受此[self removeChildByTag:1000 cleanup:YES];影响?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-28 04:36:02

只有一个具有给定标记的视图被删除。

但是,您可以使用以下代码扩展CCNode,以删除所有子级

代码语言:javascript
复制
-(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--;
    }
}

注意:这是一个要集成到Cocos2D中的proposed solution,但尚未实现。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8648434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档