clsSFX // FadeOut previous articulation when machine-gun-triggering.

This commit is contained in:
ShikiSuen 2022-05-29 13:48:58 +08:00
parent 7aca829f03
commit 69be62bb69
1 changed files with 7 additions and 1 deletions

View File

@ -34,10 +34,16 @@ public class clsSFX: NSObject, NSSoundDelegate {
private var currentBeep: NSSound? private var currentBeep: NSSound?
private func beep() { private func beep() {
let defaultVolume: Float = 0.4
// Stop existing beep // Stop existing beep
if let beep = currentBeep { if let beep = currentBeep {
if beep.isPlaying { if beep.isPlaying {
for i in 1..<30 {
beep.volume = (defaultVolume / Float(i))
usleep(1000)
}
beep.stop() beep.stop()
beep.volume = defaultVolume
} }
} }
// Create a new beep sound if possible // Create a new beep sound if possible
@ -54,7 +60,7 @@ public class clsSFX: NSObject, NSSoundDelegate {
return return
} }
beep.delegate = self beep.delegate = self
beep.volume = 0.4 beep.volume = defaultVolume
beep.play() beep.play()
currentBeep = beep currentBeep = beep
} }