2

I have an iOS 10 SpriteKit project where I'm trying to put actions on particles from a basic particle emitter created from the "snow" particle template in Xcode 8:

let snowPath = Bundle.main.path(forResource: "Snow", ofType: "sks")!
snowEmitter = NSKeyedUnarchiver.unarchiveObject(withFile: snowPath) as! SKEmitterNode
snowEmitter.position = CGPoint(x: 0, y: size.height / 2)
snowEmitter.particlePositionRange = CGVector(dx: size.width, dy: 0)
snowEmitter.particleAction = SKAction.scale(to: 3, duration: 3)
effectLayer.addChild(snowEmitter) // effectLayer is a SKNode on the scene

The emitter works as it should, but no matter what kind of SKAction I set particleAction to it gets ignored. Has anyone else experienced this?

Update: Doesn't work with Xcode 7 and iOS 9 either.

Bjørn Olav Ruud
  • 1,458
  • 2
  • 13
  • 14

3 Answers3

1

I think this still might be a leftover iOS 9 bug, not 100% sure. I just tried myself and I cannot get it to work as well.

SKEmitterNode particleAction not working iOS9 Beta

Can you not achieve the same effect using the particles settings directly in snow.sks in the inspector on the right?

You are probably looking at †hose two settings and its subsettings.

1) Particle life cycle (start, range)

2) Particle scale (start, range, speed)

This article has a nice description of each setting.

http://www.techotopia.com/index.php/An_iOS_8_Sprite_Kit_Particle_Emitter_Tutorial#Particle_Birthrate

As a general tip

Your code is not very safe in the first 2 lines because you force unwrapped the snow particle. If you ever change the name and forget about it or the file becomes corrupted than you will crash. You should change it to something like this

guard let snowPath = Bundle.main.path(forResource: "Snow", ofType: "sks") else { return } // or if let snowPath = ...
snowEmitter = NSKeyedUnarchiver.unarchiveObject(withFile: snowPath) as? SKEmitterNode
...

You can also simply this code a lot by simple saying this where you define your snowEmitter property

let snowEmitter = SKEmitterNode(fileNamed: "Snow")

This will return an optional as well, just like your old code. Than in your method where you set up the emitter say something like this (dont use !)

if let snowEmitter = snowEmitter {
    snowEmitter.position = 
    ...
}

Hope this helps

Community
  • 1
  • 1
crashoverride777
  • 10,581
  • 2
  • 32
  • 56
  • Actions work, see http://stackoverflow.com/questions/39298383/background-animation-with-depth-in-spritekit/39317134#39317134 – Knight0fDragon Sep 14 '16 at 17:02
  • @crashoverride777 The particle settings are not enough. I want the particles to "sway" from side to side as they move towards the bottom of the screen, so velocity, acceleration and angle isn't enough. I realize the code is unsafe, it was only meant for a quick experiment. – Bjørn Olav Ruud Sep 14 '16 at 19:51
  • 1
    @Knight0fDragon That example shows particleAction _not_ working. They should be rotating, but do not. I tried that code in Xcode 8 and iOS 10, and particleAction has no effect. – Bjørn Olav Ruud Sep 14 '16 at 19:53
  • @bjornruud. What are you talking about. It is rotating. How else you do explain the texture of the stars changing – Knight0fDragon Sep 14 '16 at 19:57
  • And i mean dancing, not twinkling – Knight0fDragon Sep 14 '16 at 20:01
  • 1
    @Knight0fDragon That is the twinkle part of the code, set on particleColorSequence on the emitter. They don't seem to be rotating to my eyes? Anyway, they are definitely not rotating using the exact same code in the project I created in Xcode 8. – Bjørn Olav Ruud Sep 14 '16 at 20:04
  • @BjornRuud you are right, it is not the twinkle doing the moving either though, no idea what is causing them to move, I guess the scaling from 2208 to 1920. I tried playing around with getting the individual particle, it appears they are not even SKNodes, so any chance of a hack may be out. (I had a gut feeling that the speed of the particle is at 0, so any actions would fail on it) – Knight0fDragon Sep 15 '16 at 14:30
0

There's another way to achieve the goal.

Make two or more particle systems.

Create two or more noise fields.

Bitmask match one each of the particle systems to one of the noise fields.

Put the noise fields down the bottom, where you want the wiggles to happen

Adjust the noise fields to taste.

Confused
  • 6,048
  • 6
  • 34
  • 75
0

As a 2021 datapoint, whilst adding particle emitters to Touchgram, I spent a couple of days exploring this. I came to the conclusion that they were broken in iOS9 and never fixed.

Andy Dent
  • 17,578
  • 6
  • 88
  • 115