我在我的应用中添加了背景和爆炸粒子效果。背景和精灵一起工作很好,但爆炸效果出现在背景后面。背景的zposition设置为零,一些帮助是合法的。
background = SKSpriteNode(imageNamed: "Starfield")
background.size = CGSize(width: 430, height: 700)
background.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 )
self.addChild(background)
background.zPosition = 0
func explosion(pos: CGPoint) {
var emitterNode = SKEmitterNode(fileNamed: "Explosion.sks")
emitterNode!.particlePosition = pos
self.addChild(emitterNode!)
// Don't forget to remove the emitter node after the explosion
self.runAction(SKAction.waitForDuration(2), completion: { emitterNode!.removeFromParent() })
}
答案 0 :(得分:0)
以下是任何需要它的人的解决方案。
func explosion(pos: CGPoint) {
var emitterNode = SKEmitterNode(fileNamed: "Explosion.sks")
emitterNode!.particlePosition = pos
self.addChild(emitterNode!)
// Don't forget to remove the emitter node after the explosion
self.runAction(SKAction.waitForDuration(2), completion: { emitterNode!.removeFromParent() })
emitterNode?.zPosition = 2
}