DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

removeChildByTag remove multiple childrens #337

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Actual Code:
-(void) removeChildByTag:(int)aTag cleanup:(BOOL)cleanup
{
    NSAssert( aTag != kCocosNodeTagInvalid, @"Invalid tag");

    CocosNode *child = [self getChildByTag:aTag];

    if (child == nil)
        CCLOG(@"removeChildByTag: child not found!");
    else
        [self removeChild:child cleanup:cleanup];
}

NEW CODE

-(void) removeChildByTag:(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--;
    }
}
With code you can deleter multiple childrens.

Sprite *sprite1=[Sprite spriteWithFile:@"1.gif"];
Sprite *sprite2=[Sprite spriteWithFile:@"1.gif"];
Sprite *sprite3=[Sprite spriteWithFile:@"1.gif"];
[self addChild:sprite1 z:0 tag:1];
[self addChild:sprite2 z:0 tag:1];
[self addChild:sprite1 z:0 tag:1];
[self removeChildByTag:1 cleanup:NO];

Original issue reported on code.google.com by manu.valladolid on 27 Apr 2009 at 12:20

GoogleCodeExporter commented 9 years ago
So tag could be fully used to "group" sprite together. Nice.

Original comment by sfl...@gmail.com on 2 May 2009 at 3:57

GoogleCodeExporter commented 9 years ago
rename to removeChildrenByTag.

Original comment by manu.valladolid on 3 May 2009 at 3:09

GoogleCodeExporter commented 9 years ago

Original comment by ricardoq...@gmail.com on 28 Nov 2009 at 12:47