How do I resume a performSelector method after being paused?
I've looked around on stack overflow for days and have not seen an answer to my problem. I have several methods in my main game scene that are called by
[self performSelector:@selector(MethodName) withObject:nil afterDelay:.1];
When I leave the game and come back, it looks like all of my methods run at once. I assume this is because the delay time is calculating in the background, but I do not understand how to correct this in cocos2d. I thought I didn't need to deal with NSTimers with the pause/resume functions in cocos2d? What simple piece of information am I missing here?
You can use cocos-2d schedulers to solve this problem. See the below code:
[className schedule: @selector(selectorName) interval:2];
When you pause the game using : [[CCDirector sharedDirector] pause]; this timer's will paused. And when you resume the game using : [[CCDirector sharedDirector] resume]; It will also resume.
Also you can create sequence of actions to make delayed single method call.
id delay = [CCDelayTime actionWithDuration: yourDuration]; id call = [CCCallFunc actionWithTarget:yourTarget selector:yourSelector]; id sequence = [CCSequence methodOne: delay two: call]; [someNode runAction:sequence];