我有一个SKEmitterNode
而我正试图在按下按钮时停止它。我以这种方式添加节点:
let followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: 2.0)
let loopAction = SKAction.repeatActionForever(followLine)
emitterNode.targetNode = scene
emitterNode.runAction(loopAction, withKey: "loop")
addChild(emitterNode)
我将emitterNode添加到我的SKScene
,当我想要停止粒子时,我尝试了所有这些可能的方法:
let action = SKAction.runBlock { [weak self] in
self?.emitterNode.particleBirthRate = 0
}
emitterNode.runAction(action)
emitterNode.removeAllActions()
emitterNode.removeFromParent()
removeAllActions()
let remove = SKAction.removeFromParent()
emitterNode.removeActionForKey("loop")
emitterNode.runAction(remove)
发射器不会停止,动画会继续。
答案 0 :(得分:0)
我发现这是我的代码的问题。我试图阻止在计算机属性中创建的发射器节点,因此在访问它的时候分配了它。实例显然不相同,发射器节点也没有停止。这是我的小费。不要将计算机属性的语法与使用闭包初始化属性的语法混淆。这两段代码非常不同:
// Created only once
var laserButton: ParticlesLoadingButton = {
let button = ParticlesLoadingButton(frame: CGRect(x: 100, y: 100, width: 200, height: 100))
button.particleEffect = .Laser
button.particleColor = UIColor.orangeColor()
return button
}()
// Created every time it is accessed
var laserButton2: ParticlesLoadingButton {
let button = ParticlesLoadingButton(frame: CGRect(x: 100, y: 100, width: 200, height: 100))
button.particleEffect = .Laser
return button
}