问题描述
我尝试了几种解决方法,但仍然无法暂停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:
- 用
self.paused = YES;
暂停场景 - 设置自定义
globalPause = YES;
变量以控制update:
方法的执行(因为update:
在场景暂停时仍然运行).
- pause the scene with
self.paused = YES;
- set custom
globalPause = YES;
variable to controlupdate:
method execution (becauseupdate:
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.
以下是可以在iOS9
上重现此问题的代码:
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
因此,一个非常简单的示例可以在iOS8
上运行,而不能在iOS9
上正常运行.发生的事情是,即使一切看起来都暂停了,但事实并非如此.取消暂停后,现有粒子将移动到场景未暂停时应该存在的位置.此外,看起来粒子也不断产生,如果暂停时间较长,则在暂停时会产生明显的滞后...
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;
它没有用,实际上这应该在场景暂停时自动完成(将发射器添加到场景中).尝试进行的另一件事是设置emitter.particleSpeed = 0;
以及emitter.particleSpeedRange = 0;
和emitter.particleBirthRate = 0;
,但这不会影响已经存在的粒子(有意义).
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...
推荐答案
要暂停场景:
currentScene.speed = 0
currentScene.paused = true
取消暂停场景
currentScene.speed = Variables.gameSpeed
currentScene.paused = false
这对您有用吗?
PS:您正在使用哪个iOS版本?我已经了解了有关iOS9.1的问题,这些问题似乎在9.3中已得到纠正.
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.
这篇关于无法在iOS9中暂停SKEmitterNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!