Reputation: 1
after so much reading, i can see there is so much miss understanding on what should i do when replacing scene. on the dealloc method, do i have to release ALL my timers ?? or cocos2d does it ??
i have 3 timers on startup:
[self schedule: @selector(contact:)];
[self schedule:@selector(tick:)];
[self schedule: @selector(randomsActions:) interval:0.1];
befor i replace the scene to menu (replaceScene) i do this :
[self unschedule:@selector(randomsActions:)] ; //stop timer
[self unschedule:@selector(contact:)] ; //stop timer
[self unschedule:@selector(contact:)] ; //stop timer
but it crashes.(i have seen people saying i do not have to unschedule them? )
so i tried this in my dealloc :
[[CCScheduler sharedScheduler] unscheduleAllSelectorsForTarget: self];
which crash it also at the second time( crashes in class: CCScheduler.m )
in my dealloc i put also this:( DO I NEED TO??? )
delete _contactListener;
[self removeAllChildrenWithCleanup: YES];
delete world;
world = NULL;
[super dealloc];
whats happen here ? can someone give me any idea on what should be done in dealloc when replacing scenes? what should i do with my timers ???
thanks .
Upvotes: 2
Views: 422
Reputation: 278
When you replace the scene, COCOS2d automatically dealloc all the scheduler you have started for the particular scene or layer. Thats why you wrote [self scheduler:...];. Cocos2d Scheduler is somewhat different than NSTimer.
You do not need to dealloc the sccheduler just keep it blank, need not to worry,
- (void)dealloc {
//memory deallocation
[super dealloc];
}
Upvotes: 2