4

There is no code to present since we're using Xcode to define the value for numParticlesToEmit for a SKEmitterNode.

Specifically, we use the Maximum property next to the Birthrate property for the Emitter section.

The Birthrate property is set to 25.

If we set Maximum to 0, particles appear as expected.

However, if we use 50, the particles do not appear. The particles appear inside of Xcode, so the values for the SKEmitterNode seem valid. The particles simply do not appear when running the app.

All we do in code is add the SKEmitterNode to the scene. Here's the code that adds the node to the scene:

    self.addChild(fireworksEmitter)

Nothing else changes besides the Maximum property.

Suggestions?

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • Two questions, when you set Maximum property to 50, 1) Do you see increased node count when add an emitter to the scene? 2) Do you see emitter working in Particle Editor? – Whirlwind Jan 18 '17 at 23:09
  • @Whirlwind yes it works in the Particle Editor, sorry that wasn't clear in the question (what was meant by `the particles appear inside of Xcode`). Good question on the node count, will check. – Crashalot Jan 18 '17 at 23:28
  • @Whirlwind The node count increases by 1 only so it seems further proof the SKEmitterNode is getting added. Any clues? – Crashalot Jan 19 '17 at 00:38
  • Not at the moment. I suggest you to take a screenshot of your Particle Editor for this particular emitter. – Whirlwind Jan 19 '17 at 08:24

2 Answers2

1

Perhaps the wonders of resetSimulation() are what you're missing.

Using this, you can set values, and "restart" a particle emitter with new values, or its existing values. This is very good for weapons effects and other short firing emissions from a particle emitter.

This also means you don't need to instantiate a particle system, only place it, and restart it whenever you need it, if you're using a system with finite particle emittance.

This is what you're exploiting - the finite particle emittance inherent to a blending of numParticlesToEmit and birthRate.

Try firing resetSimulation() a few times, to see what happens. Hope it helps.

Confused
  • 6,048
  • 6
  • 34
  • 75
  • Thanks! You're everywhere on SO. :) Already tried `resetSimulation`, but this didn't help, unfortunately. – Crashalot Jan 19 '17 at 07:43
  • This really should do it. And is the "suggested" way to use this kind of "resetting" particles. It's not the classic way to do this, but it should work just like a pulsing particle system. Can you share the particle system scene? I'll have a crack at fixing it. Particle systems is one of the few things that I do actually know a reasonable amount about. – Confused Jan 19 '17 at 13:34
  • Having said that... I know much more about 3D particle systems than I do about 2D ones... which should be simpler little cousins of the 3D ones. I've tickled SpriteKit's Particle Engine a couple of times, but I know SceneKit's system quite well. And they're somewhat similar... somewhat. This is an interesting challenge I'd like to look at more deeply. Pulsing a particle engine should be super easy, and work very well. – Confused Jan 19 '17 at 13:36
0

It sounds like the particles have already run and disappeared for some reason. You're still seeing them when the max is 0 since that lets it run forever. Is there any code where you add the particle system to the scene or is it all done through the scene editor?

I had issues with when I was instantiating the emitter node. If the node was an instance variable, it wouldn't show up, but if I created the node right before I added it to the scene, it would show up correctly.

claassenApps
  • 1,137
  • 7
  • 14
  • Sure, posted, but again, nothing changes except changing the `Maximum` property in the Particle Editor in Xcode. – Crashalot Jan 19 '17 at 00:05
  • Can you also post the code where you instantiate the emitter node? I had a problem like this a while back and it had to do with when and how I was instantiating it. – claassenApps Jan 19 '17 at 02:50
  • @Crashalot, try creating the emitter node just before you add it to the scene (rather than as an instance variable). – claassenApps Jan 19 '17 at 16:23