Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to remove a Cocos2D sprite from a layer?

JohanovskiJohanovski Posts: 343Registered Users @ @
edited May 2010 in iOS SDK Development
Hi there!

I'm working in a Cocos2D scene where I have a pack of sprites added as children in a GameScene that inherits from CCLayer. When I want to change the whole scene I know that I can remove all children with this line (if I'm not wrong, which also can be):
[self removeAllChildrenWithCleanup:YES];

However how can I remove a single sprite at a certain point of the game? I've tried the following but it doesn't work:
// myObject is a custom class that contains a pointer to it's sprite
[self removeChild:myObject.sprite cleanup:YES];

I think it should be something like what I've done, but what?

Thanks in advance for your time! :)
Post edited by Johanovski on
· ·

Replies

  • smashersmasher Posts: 3,859Registered Users @ @ @ @ @
    edited May 2010
    This code is correct, so the problem is somewhere else in your code.
    // myObject is a custom class that contains a pointer to it's sprite
    [self removeChild:myObject.sprite cleanup:YES];
    

    Try logging myObject to make sure it's not nil. Log myObject.sprite to make sure it exists, and myObject.sprite.parent and self to make sure they match.
    TinyCo is Hiring Mobile Game Programmers (C++)
    http://jobvite.com/m?3Ho5wgwr
    · ·
Sign In or Register to comment.