SKEmitterNode particles lag at start

615 views Asked by At

I'm playing around with SKEmitterNode in my own little game. I'm shooting a cannon ball and when the ball hits one of the boxes in the scene, the box gets destroyed and a particle effect with a simple texture "BOOM" is created to make a transition when the box disappears. The problem is, that when I start my emitter I expect it to start emitting the particles right away, but this is not the case and the particle is played after a short delay of 0.5-1s.

Here is my function for creating an emitter:

func createParticleEmitter(fileName: String) -> SKEmitterNode
{
    let path = NSBundle.mainBundle().pathForResource(fileName, ofType: "sks")
    assert(path != nil, "Could not find file \(fileName)")

    let obj : AnyObject? = NSKeyedUnarchiver.unarchiveObjectWithFile(path!)
    assert(obj != nil, "The emiter \(fileName) could not be created")

    return obj as! SKEmitterNode
}

Then on collision, this function is called, where position is the position of the dying object, and scene is the parent scene of the dying object:

func addOnDeathParticles(position: CGPoint, scene : SKNode)
{
    var emitter : SKEmitterNode = createParticleEmitter("boom")

    emitter.position = position

    let seq = [SKAction.waitForDuration(PARTICLE_DIE_DURATION,
               withRange:PARTICLE_DIE_DURATION_RANGE),
               SKAction.removeFromParent()]

    emitter.runAction(SKAction.sequence(seq))
    scene.addChild(emitter)
}

The action list is added to make the emitter disappear after PARTICLE_DIE_DURATION with a random value of PARTICLE_DIE_DURATION_RANGE.

As I understand it, as soon as the emitter is attached to the scene, it should start emitting particles. But as I mentioned at the beginning, this is not the case and the particles start appearing after 0.5-1 second. The particle created is just a texture that is scaling up and slowly rotating but there is no delay set (not even sure if you can do that).

Did anyone had the same behaviour or has a suggestion what I'm doing wrong? Glad for any help :)

Cheers, TK

1

There are 1 answers

0
James Takarashy On BEST ANSWER

The solution was setting the advanceSimulationTime to exactly 1.0 sec. I'm not entirely sure why this is the case, but I suppose that the creation "animation" takes up this time.

Anyway, case closed and thanks for the help to everyone, especially lchamp since he suggested the solution.