2

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];
    }

}
Alexyuiop
  • 813
  • 2
  • 10
  • 25
  • because the particles node is on one scene and you're replacing the scene with another. You wouldn't expect sprites from scene A to remain when presenting scene B either, right? – CodeSmile Jun 15 '14 at 13:19
  • No, what I mean is that I have a fade transition and while the current scene is still fading (all the sprite are still showing on the scene), I'm expecting a particle effect but it just doesn't show. The particle effect is supposed to run right when the player is hit, and I do that before transitioning to the other scene. – Alexyuiop Jun 15 '14 at 18:08
  • you may want to keep the transitioning scenes animated, skview has a flag for that – CodeSmile Jun 15 '14 at 19:16

1 Answers1

2

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

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281