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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-05-2010, 01:09 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 126
rahul7star is on a distinguished road
Default remove ccsprite

how to remove ccsprite in cosos2d
ccsprite *f=[ccsprite spritewithfile:@"a.png"];
[self addchild f z:0];

i did
[self removechild: f cleanup:YES]
but its not working
rahul7star is offline   Reply With Quote
Old 02-05-2010, 01:17 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

Quote:
Originally Posted by rahul7star View Post
how to remove ccsprite in cosos2d
ccsprite *f=[ccsprite spritewithfile:@"a.png"];
[self addchild f z:0];

i did
[self removechild: f cleanup:YES]
but its not working
Are you sure the value of "f" you're passing into removechild is the same value that you got back from [ccsprite spritewithfile: ] ? From the snippet you posted "f" looks like it's a local variable and only usable inside the method where you declared it.

You'll probably have to make f an instance variable (declared in the .h file, between the brackets of the interface) so that you can use the same variable in all methods of your class.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-05-2010, 01:19 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 126
rahul7star is on a distinguished road
Default

Hi

f is global and is already declared in.h
as ccsprite *f;

and in .mm its like
f=[ccsprite spritewithfile:@"a.png"];
[self addchild f z:0];
rahul7star is offline   Reply With Quote
Old 02-05-2010, 05:33 PM   #4 (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

Post the real code where you add and remove the sprite, and the declaration for f. If it's really global then you'll have problem when you create more than one object of this type.


You could try adding this right after adding the sprite, and again before removing the sprite, just to make sure you have the right one. If they don't match then you are removing the wrong sprite.

Code:
NSLog(@"f is %@", f );
NSLog(@"f is at address %ul", f );
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-10-2010, 08:12 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 126
rahul7star is on a distinguished road
Default

i had declared a timer
[self schedule: @selector(step];
now i want to remove this when game ends

so i am doing this
[self unschedule: @selector(step];
it work only when 1st time game ends and rest of time i can see the value i am passing in step()

code is somewhat like this
game start()
{[self schedule: @selector(step];
}
then
step()
{
if(gameEnd)
{
[self over];
}
}

over()
{
[self unschedule: @selector(step];
sceneChange
}
rahul7star is offline   Reply With Quote
Old 02-10-2010, 10:56 AM   #6 (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

Quote:
Originally Posted by rahul7star View Post
i had declared a timer
[self schedule: @selector(step];
now i want to remove this when game ends
1) What are schedule and unschedule? I don't know those methods.
2) Please use [code] [ /code] tags
3) Please explain "rest of time i can see the value i am passing in step()" -- I don't understand that that means.

Stopping an NSTimer should be as simple as [timer invalidate], timer=nil as long as timer is a pointer to the NSTimer you're trying to stop.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-10-2010, 11:01 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 126
rahul7star is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
1) What are schedule and unschedule? I don't know those methods.
2) Please use [code] [ /code] tags
3) Please explain "rest of time i can see the value i am passing in step()" -- I don't understand that that means.

Stopping an NSTimer should be as simple as [timer invalidate], timer=nil as long as timer is a pointer to the NSTimer you're trying to stop.
Hi smasher
1) schedule and unschedule are cocos2d timer event (NSTimer replacement )
2)rest of time means after 1 retry
rahul7star is offline   Reply With Quote
Reply

Bookmarks

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: 399
7 members and 392 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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