0
votes

i am doing something wrong, maybe someone could help me .

when app is start i add a sprite as a child,from DB like this :

b_pic=[CCSprite spriteWithFile:basic_pic];
    b_pic.position=ccp(160,175);
    [self addChild:b_pic];

then i do things,and run animation, so before animation starts, i remove the sprite with :

[b_pic.parent removeChild:b_pic cleanup:YES];

and then i am trying to add it back, BUT its crashes. i add it with :

b_pic=[CCSprite spriteWithFile:@"regular.png"];
    b_pic.position=ccp(160,175);
    [self addChild:b_pic];

what am i doing wrong here ? i cant understand this child and parent thing.

i have also tried to remove the sprite with :

[self removeChild:b_pic cleanup:YES];

thanks a lot .

1
Does it crash on [b_pic.parent removeChild:b_pic cleanup:YES];? try [self removeChild:b_pic cleanup:Yes];xuanweng
What does your crash stack look like and or where does it crash exactly? With cocos2d for me it most often crashes when I remove a sprite too early when something calls on it.Sup3rpanda

1 Answers

0
votes

The sprite is an autorelease object in cocos2d. So when you remove the sprite the CleanUp should be NO like so...

[self removeChild:b_pic cleanup:NO];