Unable to pause SKEmitterNode in iOS9

吃可爱长大的小学妹 提交于 2019-11-29 00:35:50

问题


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:

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


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



来源:https://stackoverflow.com/questions/32750415/unable-to-pause-skemitternode-in-ios9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!