Unable to pause SKEmitterNode in iOS9
Asked Answered
S

1

15

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...

Snide answered 23/9, 2015 at 22:15 Comment(21)
Have you found any workaround for pausing SKEmitterNode?Bodice
@Bodice Not really... Are you experiencing the same issue ?Snide
Yes. In iOS 8, everything was OK. And I tried what you said in your post, and got the same results.Bodice
Try removing it from the scene temporarily.Preach
@Owatch If you remove an emitter from its parent, the existing particles will be removed as well, and that is not what I want. I am trying to stop emitting while an app is in the background, and to continue with emitting when app returns to foreground. Also, I am trying to "pause" existing particles, and to have them continue with their movement, from the point where they left of, on app's return from background.Snide
Alright, I understand now. Thanks!Preach
Added an answer but It may just be because we are now in iOS9.3, is this still an issue for you, because as of 9.3. pause worksBarbed
@Barbed I don't see your answer.. Did you deleted it?Snide
Yes i deleted it because I was testing on 9.3, realized this was oldBarbed
@Barbed Well you could post it if you are positive that it works. I will accept it. It might be helpful for the readers... I am still on 9.1 and it doesn't work for me... So if you think it is fixed, feel free to post your answer.Snide
Well the fix is in your question already, to pause both the node and the scene, but like i said. This is on 9.3, ill get the 9.1 simulator and see if my particles do not pauseBarbed
Does it pause for you on simulator? it pauses for me on iOS 9.1 iPhone 4s simulatorBarbed
@Barbed It pauses, but the problem is unpausing ... Particles should continue from where they left of, but that is not happening...Snide
ok I will give it a try hold onBarbed
Looks like the simulation time for particles isn't pausing in 9.1, but the pausing is fixed on 9.3, I wonder if there is a notification being called to pause it particlesBarbed
@Barbed So it is obviously fixed on 9.3. That is a good news...Snide
yeah, 9.3 it works fine, sucks that things like this do not get fixed till the next iteration of iOS, I tried advancing the simulation time by a negative number, that doesn't workBarbed
@Barbed Yeah...At least it works on iOS9.3... I tried many different ways to get this working on iOS9.1 (pausing emitter node, changing its speed, playing with particle birth rate etc etc) and nothing really worked.Snide
well I know what we can do, get the time that the emitter has been playing before the pause button, then reset the simulator and use advanceSimulationTime to reset it on unpauseBarbed
Theoretically, that could work... Will try it just for fun as soon as I find time. Personally I am not a fan of those workarounds. If something doesn't work, I skip it. I use something else. Still, it make sense what you are saying and hopefully it might be a nice workaround.Snide
Yeah, I do not like them either, but apple really does't give a choice, and I am not a fan of forcing people to upgrade their phones or not use my app (My 6+ is still on iOS 8)Barbed
Y
1

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.

Y answered 24/6, 2016 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.