停止 SKAudioNode 播放
Stop SKAudioNode from Playing
我试图仅在玩家移动时播放脚步声。我添加了一个检查来查看播放器是否已经在移动,以确保它不会在彼此之上播放音频。
出于某种原因,footstepSound.run(SKAction.stop())
无法正常工作,导致一堆曲目相互重叠,听起来很糟糕。
有什么想法吗?
let footstepSound = SKAudioNode(fileNamed: "Footsteps.mp3")
if (degree != 50) {
if (isFootstepping) { return }
isFootstepping = true
self.addChild(footstepSound)
}
else if (isFootstepping && degree == 50) {
isFootstepping = false
footstepSound.run(SKAction.stop())
footstepSound.removeFromParent()
}
已解决!问题是 footstepSound 变量没有全局声明。这会导致在每次函数调用时创建一个新变量,因此当调用 .removeFromParent 时它永远不会引用旧变量。
我试图仅在玩家移动时播放脚步声。我添加了一个检查来查看播放器是否已经在移动,以确保它不会在彼此之上播放音频。
出于某种原因,footstepSound.run(SKAction.stop())
无法正常工作,导致一堆曲目相互重叠,听起来很糟糕。
有什么想法吗?
let footstepSound = SKAudioNode(fileNamed: "Footsteps.mp3")
if (degree != 50) {
if (isFootstepping) { return }
isFootstepping = true
self.addChild(footstepSound)
}
else if (isFootstepping && degree == 50) {
isFootstepping = false
footstepSound.run(SKAction.stop())
footstepSound.removeFromParent()
}
已解决!问题是 footstepSound 变量没有全局声明。这会导致在每次函数调用时创建一个新变量,因此当调用 .removeFromParent 时它永远不会引用旧变量。