Search code examples
iosobjective-csprite-kitsksceneskemitternode

Particle Effects Disappear When Transitioning to a New SKScene


I'm working on a game using Sprite Kit. I have a particle effect that runs when an object collides with another object; however, this particle effect seems to disappear when I add a transition to another SKScene. What's causing this disappearance, and how do I solve this issue?

Edit: By disappear I mean that it does not appear in the current scene when the scene is still transitioning with all the sprites still showing. It has a 2 second time interval, so shouldn't I be able to see it?

Here's the code for the particle effect and scene transition:

- (void)player:(SKSpriteNode *)player didCollideWithEnemy:(SKSpriteNode *)enemy {
    Enemy *monster = (Enemy *)enemy;
    if(!monster.isMoving){
        SKEmitterNode *emitter =  [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"]];
        emitter.position = player.position;
        [self addChild: emitter];
        isAlive = FALSE;
        NSLog(@"Hit");
        CrowdedData *crowdedData = [CrowdedData sharedManager];
        crowdedData.score = score;
        [player removeFromParent];


        SKTransition *reveal = [SKTransition fadeWithDuration:2];   
        GameOver *scene = [GameOver sceneWithSize:self.view.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        [self.view presentScene:scene transition:reveal];
    }

}

Solution

  • SKTransition has two properties that are relevant to this:

    [transition setPausesOutgoingScene:NO];
    [transition setPausesIncomingScene:NO];
    

    Both default to YES, causing either the outgoing in incoming scenes to be paused, which in turn pauses your emitter. For your purposes, setting the pausesOutgoingScene property to NO should be enough to fix this. More info in the docs:

    https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKView/Reference/Reference.html