Reputation: 854
I am currently making a game in Cocos2D, and I need to pause/resume some particle systems in order to optimize.
How can I do this?
I am aware that I can use [particleSystem unscheduleUpdate] and [particleSystem scheduleUpdate], but how can I check if an update IS scheduled already?
I want to pause all particle systems that are off screen, and resume them when they get back in view, so I am looping through my particle systems when I move my viewport.
particleSystem.active does not seem to give me the desired flag to check whether the system is updating or not...
What am I missing here?
Upvotes: 2
Views: 1774
Reputation: 542
Another trick that I used, was setEmissionRate() function. To pause particle system:
setEmissionRate(0);
To resume particle system:
setEmissionRate(latestValue);
I hope this should be good for you :)
Upvotes: 1
Reputation: 64477
You should not schedule or unschedule the update method of a particle system, or any other internal class for that matter. The problem with that is that there may be other scheduled methods (ie scheduled with priority or interval) that would then keep running.
Instead, you should use pauseTarget and resumeTarget of the CCScheduler class pause/resume updates of a class instance:
[[CCScheduler sharedScheduler] pauseTarget:particleSystem];
[[CCScheduler sharedScheduler] resumeTarget:particleSystem];
This will pause/resume all scheduled methods, not just the regular update method.
You can also check if a target's scheduled methods are paused:
[[CCScheduler sharedScheduler] isTargetPaused:particleSystem];
Upvotes: 4