【发布时间】:2017-08-11 02:24:04
【问题描述】:
目标是为来自SKEmitterNode, 的粒子设置动画,但以下代码不起作用。粒子不会改变纹理。它们只显示生命周期中的第一个纹理——或者更具体地说,是 Xcode 粒子编辑器中使用的原始图像。
粒子生命周期比帧持续时间长,所以这不是问题。
// Create animation textures
let animationAtlas = SKTextureAtlas(named: atlasFilename)
var animationFrames = [SKTexture]()
// Set number of animation frames
let numImages = animationAtlas.textureNames.count
// Load texture array
for i in 0..<numImages {
let textureName = "\(texturePrefix)\(i)"
animationFrames.append(animationAtlas.textureNamed(textureName))
}
// Create emitter node w/ animation on each particle
let emitterNode = SKEmitterNode(fileNamed: EmitterFilename)!
let animation = SKAction.animate(with: animationFrames, timePerFrame: 0.05)
emitterNode.particleAction = animation
// Define fade out sequence
let fadeOut = SKAction.fadeOut(withDuration: sparkleFadeOutDur)
let remove = SKAction.removeFromParent()
let sequence = SKAction.sequence([fadeOut, remove])
// Add emitter node to scene
addChild(emitterNode)
emitterNode.run(sequence)
【问题讨论】:
标签: ios animation sprite-kit skaction