ios - 背景 block 粒子效果

标签 ios swift

我向我的应用程序添加了背景和爆炸粒子效果。背景和 Sprite 一起工作得很好,但爆炸效果出现在背景后面。背景的 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() })

}

最佳答案

这是为有需要的人提供的解决方案。

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

}

关于ios - 背景 block 粒子效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36206060/

相关文章:

ios - fetchedResultsController fetchedObjects 返回 NSCFString 而不是 NSArray

IOS/ Storyboard : Images Disappear from identity inspector after lengthy Redos but still visible in Storyboard

ios - Linkedin ios SDK createSessionWithAuth更新错误

ios - Swift 计数停止在错误的数字

ios - Swift:以 NSException 类型的未捕获异常终止

swift - 另一个 View Controller 的 IBOutlet 为 nil

iphone - 我的代码片段泄露了

ios - 如何一天只重复一次 LocalNotification

swift - 框架问题 - 模块文件是由旧版本的编译器创建的

ios - SpriteKit 横向方向不起作用