2

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?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217

2 Answers2

4

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];
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • 1
    Thanks a lot! You are always very helpful :) I have not gotten it to work yet though. I am running this check, but it keeps triggering all the time: if([[CCScheduler sharedScheduler] isTargetPaused:particleSystem] == NO) { [[CCScheduler sharedScheduler] pauseTarget:particleSystem]; NSLog(@"STOPPED PARTICLESYSTEM"); } Edit: Why am I not able to format this comment? I look stupid now. – Simen Øian Gjermundsen Nov 03 '11 at 15:56
  • I believe the very first frame all scheduled targets will be set as paused. Try running this in an update method, or onEnter. AFAIK comments don't support formatting. – CodeSmile Nov 03 '11 at 16:46
1

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 :)

mostafa88
  • 532
  • 1
  • 8
  • 20