SKEmitterNode particleAction not working iOS9 Beta

强颜欢笑 提交于 2019-11-30 21:10:47

iOS9 SKEmitterNode targetNode property problem.

When the targetNode property is set the particles will emit at zPosition 0. It doesn't matter if you have set zPosition to be anything else, the particles will still render at zPosition 0. If you print the value of zPosition to the console it will report back whatever you have set it to. If you set targetNode = nil, the particles will render on correct layer.

Solution: I reordered all my background sprites to be <= -1

hope this helps, I'm going to file a bug report, also I added an example repo on github. https://github.com/fromkey/iOS9_BUG_SKEmitterNode_targetNode/tree/master

Can confirm this on iOS 9 beta 5. .particleAction seems to have stopped working completely! Hoping Apple fix in the next beta/GM build.

One of my new games rely on this so a little nervous at the moment!

I had a similar problem myself, however the issue for me was that my code was setting the targetNode property like so:

class GameScene : SKScene {
    func addEmitter(fileName: String, position: CGPoint) {
        let particle = SKEmitterNode(fileNamed: fileName)!
        particle.position = position
        //particle.targetNode = self // DOES NOT WORK ON iOS 9 BETA
        self.addChild(particle)
        // Don't forget to remove the emitter node after the explosion
        self.runAction(SKAction.waitForDuration(2), completion: { particle.removeFromParent() })
    }
}

Removing the particle.targetNode line resulted in the particles being rendered again. Tested on iOS 9 beta 6.

Updated to show full usage within a SKScene.

I had a same problem in iOS 9.

Juet remove the targetNode property, and it will work again.

I was having the same problem when creating an SKEmitterNode that's nested in a Scene file. I ended up iterating all the nodes, finding the emitters and making copies of them. Then it started working again.

for (SKNode *node in containerNode.children) {
    if ([node isKindOfClass:[SKEmitterNode class]]) {
      SKEmitterNode *e = (SKEmitterNode *)node;
      [e removeFromParent];

       SKEmitterNode *new = [e copy];
       [containerNode addChild:new];
    }
 }

If you don't want to lose the functionality that targetNode gives you, then what I've found works, is to assign a zPosition value to both the emitter, and the emitted particles.

I normally set up an enum to provide me with Z position value for all nodes like:

typedef enum {
  kZBG = 0,
  kZSpaceship = 10,
  kZBullets = 15,
  kZSpark = 20,
} NodeZOrder;

I then use this in my emitted with:

NSString *sparkPath = [[NSBundle mainBundle] pathForResource:@"spark" ofType:@"sks"];
self.sparkEmitter = [NSKeyedUnarchiver unarchiveObjectWithFile:sparkPath];
self.sparkEmitter.targetNode = self.background;
self.sparkEmitter.zPosition = kZSpark;
self.sparkEmitter.particleZPosition = kZSpark;

I found that this works fine. My particles stay where I want them on the background, and they are all visible on both iOS 9 and iOS 10.

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