我有一个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)发射器没有停止,动画还在继续。
发布于 2016-02-14 19:38:28
我发现我的代码出了问题。我试图停止一个发射器节点,该节点是在一个计算机属性中创建的,因此在访问它的时候被分配给了它。实例显然不一样,发射器节点也没有停止。这是我的小费。不要将计算机属性的语法与使用闭包初始化属性的语法混淆。这两段代码非常不同:
// 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
}https://stackoverflow.com/questions/35297546
复制相似问题