Removing sprite with touch, bomb, or after CCFadeout?

I have a sprite (that appears infinitely on the screen) that should be removed by one of three ways:

1- Tap the sprite (adds to the score) 2- Tap a bomb that removes all sprites (adds to the score) 3- The sprite auto removes itself when it fades out (does not add to the score). The 3rd method is not working properly

For the first and second methods I’m using the general idea of :

 for (ball in ballsArray)
    {

        if (CGRectContainsPoint(ball.boundingBox, location))
                    {




    [ballsKillArray addObject:ball];



        score = score +1;
                         sharedGameManager.score= score;
        NSLog(@"%d",score);
                    }

    }


for (ball in ballsKillArray)
{
    [spriteSheet removeChild:ball cleanup:YES];
    [ballsArray removeObject:ball];
    [self removeChild:ball];

}

[ballsKillArray removeAllObjects];}

And for adding the sprite and performing the fadeout-then-remove I am using: (this is used every time a ball is being allocated which is done by an update method every certain time)

-(void)spawnBall:(ccTime)delta
 {
 ball = [[Ball alloc]init];
[spriteSheet addChild:ball];
[ballsArray addObject:ball];

id fade = [CCFadeOut actionWithDuration:3];

CCAction *removeBAll = [CCCallFuncN actionWithTarget:self selector:@selector (removeSelf)];


CCSequence *actionThenRemove = [CCSequence actions: fade,removeBall, nil];


  [ball runAction:actionThenRemove];
}

And the removeSelf method to remove the sprite is:

 -(void) removeSelf
 {


   for(ball in ballsArray)
{
[ballsKillArray addObject:ball];



}
 for(ball in ballsKillArray)

{

[ballsArray removeObject:ball];

[self removeChild:ball cleanup:YES];

[spriteSheet removeChild:ball cleanup:YES];


}

[ballsKillArray removeAllObjects];}

The problem is i that the sprites after they perform the ccfadeout sequence are not removed as they should and i’m seeing weird behavior.

Any help is much appreciated.

The problem with your removeSelf method is it looks like it’s set up to remove all the balls on the screen, when actually you only want to remove one particular ball.

To see one way to do this, check out this tutorial - it’s a little old but should give you the general idea:

In particular check out the code when a projectile is spawned:

[projectile runAction:
     [CCSequence actions:
      [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
      [CCCallBlockN actionWithBlock:^(CCNode *node) {
         [node removeFromParentAndCleanup:YES];
    }],

Note that it uses CCCallBlockN, which takes a parameter of the object that the action is called upon - (i.e. the spawned projectile) - you can then use that to remove it from the parent. Hope that helps and good luck!