Hello I am making a Cocos2d side scroller. I have a CCSprite that I add using the [self addChild:sprite];
method. After a while I want the CCSprite to be removed. I tried the [self removeChild:sprite cleanup:YES];
method and it gave me a thread bad access error. Is this the only way to remove a child in Cocos2d?? Is there an alternate way?? I am a beginner to Cocos2d and objective c so any help is valuable.
Asked
Active
Viewed 142 times
0

PoKoBros
- 701
- 3
- 9
- 25
2 Answers
0
As far as I know, removeChild:cleanup:
is the way to go if you need to remove any CCNode
. Have you checked that sprite
is not released before trying to remove it?

ssantos
- 16,001
- 7
- 50
- 70
-
so in my app I want the character to move to the tiger so i have this code CCMoveTo* moveToTheTiger = [CCMoveTo actionWithDuration:1.0 position:ccp(tiger.position.x + 90, tiger.position.y + 90)]; [character runAction:moveToTheTiger]; but it makes another character so i have two characters on the screen. Why does this happen. i first create the character in the init method and then call another method which is where I tell the character to move. – PoKoBros Aug 18 '13 at 23:16
-
Mmh not sure if I understand the problem. Are you getting two `character` sprites on screen where you would expect just one? If that's the case, chances are you're calling something like `[self addChild:character` twice. – ssantos Aug 18 '13 at 23:28
0
[sprite removeFromParentAndCleanUp:YES]
If you have a bad access it means object is nill. Check if your sprite exist before you try to remove it.

K1laba
- 154
- 2
- 5