0
votes

For some reason my remove function on my CCNode is not working after the animation is run.

I am adding a CCNode on click, running a animation then running the remove function.

         // loads the Coin
         CCNode* coin = [CCBReader load:@"heros/coin"];
         coin.name =@"coin";
         // position
         coin.position = ccpAdd(_touchNode.position, ccp(0, 0));

         //Add to Parent
         [_touchNode addChild:coin z:-1];

         id action1 = [CCActionMoveTo actionWithDuration:0.7f position:ccpAdd(_touchNode.position, ccp(0, 200))];
         id action2 = [CCActionMoveTo actionWithDuration:0.7f position:ccpAdd(_touchNode.position, ccp(0, 100))];
         CCActionCallFunc *callAfterMoving = [CCActionCallFunc actionWithTarget:self selector:@selector(cleanupSprite:)];
         [coin runAction: [CCActionSequence actions:action1, action2, callAfterMoving, nil]];

using the following delete function produces a crash error with This node does not contain the specified child

- (void) cleanupSprite:(CCNode*)inSprite
{
    // call your destroy particles here
    // remove the sprite
    [self removeChild:inSprite cleanup:YES];
}

Using the following delete also doesn't work

- (void) cleanupSprite:(CCNode*)inSprite
{
    // call your destroy particles here
    // remove the sprite
    [self removeChildByName:@"coin" cleanup:YES];
}
1
_touchNode contains coin, if i read your code correctly.YvesLeBorg
yes but I need only the coin to be removed. I was looking at tag but it doesn't seem to exist in cocos2d v3. That right?Allreadyhome

1 Answers

1
votes

self does not contain coin, _touchNode does. Do this in your callback :

[_touchNode removeChildByName:@"coin" cleanup:YES];