开发者

crash when add and remove sprite in cocos2d

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 a开发者_JAVA百科dd 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 .


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜