0

I have a question about how to implement a particle emitter into a pre-existing pause, resume, and restart framework.

Right now I have a pause method that includes this code:

void GamePlayLayer::pause()
{
    //pauses/resumes game mechanics
    if(!isPaused){
        pauseSchedulerAndActions();
        isPaused = true;
        cout << "\npaused game... isPaused = " << isPaused;
    }else{
        resume();
    }

    //pauses/resumes particle emitters
    CCParticleSystemQuad* runner_emitter = runner.getExistingEmitter();
    if(runner_emitter != NULL){
        if(!isPaused){
            runner_emitter->pauseSchedulerAndActions();
        }else{
            runner_emitter->resumeSchedulerAndActions();
        }
    }
}

I also have a particle emitter created with the following:

CCParticleSystemQuad* Runner::getNewEmitter()
{
    p_emitter = CCParticleSystemQuad::create("emitter_runner.plist");

    //position is relative to the point we add it to -- use this so it follows the sprite when the runner moves
    p_emitter->setPositionType(kCCPositionTypeRelative);

    updateEmitterPosition();

    p_emitter->retain();
    //so we dont get extra emitters sticking around in the scene
    p_emitter->setAutoRemoveOnFinish(true);
    cout <<endl << "Emitter sent";
    return p_emitter;
}

The particle emitter in question has a duration associated with it, lets say 2 seconds. Right now, I want my pause method to freeze the particle system so that when I un-pause, the particle emitter continues where it left off.

The issue I am running into now is that when I pause, the particle emitter continues. The "pauseSchedulerAndActions()" method is decoupled from the particle emitter, which I understand has its own scheduler.

No matter what I try I am not able to stop the particle emitter from continuing to move through the time as set in the p_emitter.setDuration() method.

This is problematic because if I pause when the particle emitter has not yet reached its duration, by the time I unpause the duration is up and it has been removed because I set this flag:

p_emitter->setAutoRemoveOnFinish(true);

when creating the emitter. Also, the emitter never actually pauses, so it gives the impression that the game doesn't actually pause.

So my question is, how do I completely freeze the particle emitter in a way that allows the emitter to resume when I un-pause?

nmio
  • 778
  • 5
  • 19

1 Answers1

1

Looks like a stupid mistake on my part!

In this block of code you can see that I set isPaused before i should have. This prevented the second if statement being entered when it should have been.

//pauses/resumes game mechanics
if(!isPaused){
    pauseSchedulerAndActions();
    isPaused = true;  <-- prematurely set to true
    cout << "\npaused game... isPaused = " << isPaused;
}else{
    resume();
}

//pauses/resumes particle emitters
CCParticleSystemQuad* runner_emitter = runner.getExistingEmitter();
if(runner_emitter != NULL){
    if(!isPaused){  <-- still expected isPaused = false
        runner_emitter->pauseSchedulerAndActions();
nmio
  • 778
  • 5
  • 19