13

I'd like to add a particle to my SpriteKit app, but I can't find how to do it. I'm able to create using the particle editor, but how do I add them to my view?

Thanks a lot in advance!

san
  • 3,350
  • 1
  • 28
  • 40
noloman
  • 11,411
  • 20
  • 82
  • 129

1 Answers1

22

Lets say that you have a particle already created called MyParticle.sks.

First, you have to create a SKEmitterNode with your particle:

NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
SKEmitterNode *myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];

Now that the node is created, you can edit some parameters if you want:

    myParticle.particlePosition = CGPointMake(100, 100);
    myParticle.particleBirthRate = 5;

And the add it to your scene:

[self addChild:myParticle];

This has to be added to your SKScene

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • 1
    You can refer to the video during WWDC. Introduction to Sprite Kit and Designing Games with Sprite Kit https://developer.apple.com/wwdc/videos/ – user1872384 Sep 20 '13 at 06:07
  • I gave this a try, but I keep running into an error " No Visible @interface for 'ViewController' declares the selector 'addChild:' " any tips? – vzm Oct 27 '13 at 07:59
  • 2
    You should add this to an SKScene, not to a UIViewController. – Ben-G Nov 04 '13 at 02:48
  • This has changed a LOT in 5 years, again, this is now very easy: http://stackoverflow.com/a/43075797/294884 – Fattie Jul 15 '17 at 22:59