Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-13-2010, 01:44 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Johanovski is on a distinguished road
Default How to remove a Cocos2D sprite from a layer?

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):
Code:
[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:
Code:
// 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!
Johanovski is offline   Reply With Quote
Old 05-13-2010, 09:52 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

This code is correct, so the problem is somewhere else in your code.
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
children, cocos2d, layer, remove, sprite

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
12 members and 300 guests
Abidullah, ajay123123, cgokey, Fstuff, guusleijsten, HemiMG, jbro, n00b, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0