Search code examples
ios7sprite-kitparticlesskemitternode

how to add particles using SpriteKit in iOS7


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!


Solution

  • 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