how to add particles using SpriteKit in iOS7
Asked Answered
V

1

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!

Valma answered 19/9, 2013 at 9:52 Comment(1)
C
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

Conquistador answered 19/9, 2013 at 9:55 Comment(4)
You can refer to the video during WWDC. Introduction to Sprite Kit and Designing Games with Sprite Kit developer.apple.com/wwdc/videosCreeper
I gave this a try, but I keep running into an error " No Visible @interface for 'ViewController' declares the selector 'addChild:' " any tips?Allister
You should add this to an SKScene, not to a UIViewController.Padishah
This has changed a LOT in 5 years, again, this is now very easy: https://mcmap.net/q/399407/-how-to-add-particle-effects-to-an-ios-app-that-is-not-a-game-using-ios-7-spritekit-particleWarrantee

© 2022 - 2024 — McMap. All rights reserved.