5

I'm testing my app in iOS9 Beta 4 and finding lots of code that used to work in iOS8 that is no longer performing as expected. Another example is SpriteKit's SKEmitterNode "particleAction" property. The following code worked in iOS8 but does not work on iOS9:

// create the particle movement action
SKAction *move = [SKAction moveByX:100 y:100 duration:5]; // also, I've tested several other SKActions, such as scaleBy, fade, rotate, to no effect here        

// create a target node and add to the SKScene
SKNode *targetNode = [SKNode node];
targetNode.position = origin;
[mySKSceneNode addChild:targetNode];

// add an emitter node that has a target and an SKAction
SKEmitterNode *flameTrail = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle]pathForResource:@"FlameAttack" ofType:@"sks"]];
flameTrail.position = origin;
flameTrail.particleAction = move; // TODO iOS9 compatibility issues!
flameTrail.targetNode = targetNode;
[mySKSceneNode addChild:flameTrail];

On iOS8 the code above would yield an SKEmitterNode that looked like sparks flying. On iOS9 the SKEmitterNode is totally invisible (does not appear in the SKScene at all). If I comment out the following line:

flameTrail.particleAction = move; // TODO iOS9 compatibility issues!

then I will see the SKEmitterNode in the scene but I will not see any motion associated with the particles.

I've also tested this with several other SKActions and didn't see any change in results. I submitted a bug to Apple; in the meantime can anyone confirm/deny this problem or see a problem in the code?

user2821647
  • 407
  • 2
  • 15

6 Answers6

3

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

Michael Kennedy
  • 523
  • 1
  • 4
  • 8
  • 1
    I tried varying zPosition and adding/removing the targetNode; however I'm still having problems with particleAction. My SKEmitterNode works fine if the particleAction property is nil. Adding any SKAction to particleAction causes the SKEmitterNode to just disappear from the SKScene... – user2821647 Sep 18 '15 at 04:06
  • @user2821647, `SKEmitterNode` is also disappearing on OS X El Capitan (GM) when the `particleAction` property is set. – Milos Sep 22 '15 at 10:16
  • The problem I found with this idea, apart from the fact that it didn't work very well, was that if you have a touch sensitive node contained within a node with a negative zPosition, touches are not passed to the touch sensitive node. My answer below seems to work without this complication. – PKCLsoft Jan 10 '17 at 13:36
1

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!

HarryGT
  • 56
  • 4
0

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.

bizz84
  • 1,964
  • 21
  • 34
  • Were you able to get particleAction to work on ios9 beta 6? Can you post the entire working code so I can test on my end? My target node is not the parent like in your answer. But I would really like to see particleAction working just for a sanity check! – user2821647 Aug 27 '15 at 11:21
  • I was not using particleAction at all - I updated the sample code with my usage case - all particle properties are preset in the particle editor. – bizz84 Aug 27 '15 at 11:56
  • What happens if you remove the targetNode line also? It may be that your particles will appear but then you need to find another way to make it work in your hierarchy. – bizz84 Aug 27 '15 at 11:59
  • 1
    sorry for the delay; finally gave this some serious testing and I am still unable to get particleAction working on iOS9 Beta 5. I tried removing the targetNode and didn't see any results. The problem for me seems to be with the particleAction property. If I leave particleAction nil then the node appears. If I assign any SKAction to particleAction the SKEmitterNode just disappears from the screen... – user2821647 Sep 03 '15 at 03:29
0

I had a same problem in iOS 9.

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

Tony Peng
  • 13
  • 2
0

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];
    }
 }
jervine10
  • 3,039
  • 22
  • 35
0

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.

PKCLsoft
  • 1,359
  • 2
  • 26
  • 35