spritekit: trouble with particle keyframe sequence

房东的猫 提交于 2019-12-12 01:49:41

问题


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:


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])


来源:https://stackoverflow.com/questions/27476390/spritekit-trouble-with-particle-keyframe-sequence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!