Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to pause SKEmitterNode in iOS9

I've tried few workarounds, but still I can't pause existing particles on iOS9. I am using following technique to pause the scene:

  • pause the scene with self.paused = YES;
  • set custom globalPause = YES; variable to control update: method execution (because update: still runs while scene is paused).

The point is that I don't pause the view, but rather the scene. I don't pause the view, because of this.

Here is the code which can reproduce this issue on iOS9:

#import "GameScene.h"

@interface GameScene ()

@property (nonatomic, strong)SKEmitterNode *emitter;

@end

@implementation GameScene


-(void)didMoveToView:(SKView *)view {


    [self addChild:[self getSpaceDustEmitter]];

}

//No need for this method though :)

-(SKEmitterNode*)getSpaceDustEmitter{

    self.emitter =  [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"spacedust" ofType:@"sks"]];
     self.emitter .name = @"emitter_spacedust";
    self.emitter .position = CGPointMake(CGRectGetMidX(self.frame),self.frame.size.height);



    return  self.emitter ;
}


@end

So, very simple example which works on iOS8 and not working as expected on iOS9. What happens is that even if everything looks that is paused, its not. Existing particles after unpausing move to the point where they should be if the scene was not paused. Also, it looks like that particles keep spawning too, which can produce noticeable lag when unpausing if pause was long...

Here is a screenshot from particle editor:

particle editor

Anybody have some reasonable explanation ? So far I've tried to explicitly pause the emitter:

emitterNode.paused = YES;

It didn't worked, and actually this should be done automatically when scene is paused (emitter is added to the scene). Another thing which is tried is to set emitter.particleSpeed = 0; as well as emitter.particleSpeedRange = 0; and emitter.particleBirthRate = 0; but this doesn't affect on already existing particles (which make sense).

And thats it. Not sure if this is a bug, but I am run out of ideas...

like image 843
Whirlwind Avatar asked Sep 23 '15 22:09

Whirlwind


1 Answers

To pause the scene:

currentScene.speed = 0
currentScene.paused = true

To unpause the scene

currentScene.speed = Variables.gameSpeed
currentScene.paused = false

Does that work for you?

PS: What iOS version are you working on? I've read about problems with iOS9.1, which seems to be corrected in 9.3, about those emitters.

like image 108
David Gourde Avatar answered Oct 09 '22 23:10

David Gourde