spritekit: trouble with particle keyframe sequence

726 views Asked by At

This should be really straightforward. I'm trying to have my particles fade out using a keyframe sequence.. but when I use the keyframe sequence they dont fade out at all. Not sure what I could be doing wrong.

particle creation:

static func debris(size: Int) -> Array<SKEmitterNode> {
    if size > 5 {
        fatalError("we don't have that much debris")
    }

    var debrisArr: [SKEmitterNode] = []

    for i in 1...size {
        let debris: SKEmitterNode = SKEmitterNode(fileNamed: "debris")
        debris.particleTexture = SKTexture(imageNamed: "debris\(i)")
        convertNumRef(&debris.particleScale)
        convertNumRef(&debris.particleScaleRange)
        debris.particleRotationSpeed = debris.particleRotationSpeed * CGFloat.randomSign()
        // THE PART WE CARE ABOUT
        debris.particleAlphaSequence = SKKeyframeSequence(keyframeValues: [0.5, 1.0, 0.0], times: [0.0, 3.0, 4.0])

        debrisArr.append(debris)
    }

add particles to game scene here

func makeDebris(){
    for debrisEmitter in self.debris {
        debrisEmitter.resetSimulation()
        debrisEmitter.position = self.position
        self.gameScene.gameLayer.addChild(debrisEmitter)
        debrisEmitter.runAction(SKAction.removeFromParentAfterDelay(10))
    }
}

I've tried this using a simpler example too.

fire is the default spritekit "fire" particle

let fire = SKEmitterNode(fileNamed: "MyParticle")
fire.particleColorSequence = SKKeyframeSequence(keyframeValues: [SKColor.blueColor(), SKColor.blueColor(), SKColor.yellowColor()], times: [0.0, 1.0, 2.0])
fire.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
self.addChild(fire)

the emitter is only emitting blue particles. it just picks whichever color is first in the array. I must be missing something.

1

There are 1 answers

1
hamobi On BEST ANSWER

Ok I misunderstood. the times arent the times in seconds. they are fractions of your particle's lifespan

debris.particleLifetime = 8
debris.particleAlphaSequence = SKKeyframeSequence(keyframeValues: [1.0, 1.0, 0.0], times: [0.0, 0.7, 1.0])