Fixed cut_scene.
This commit is contained in:
parent
a6702edf16
commit
998e319d92
25
sound.py
25
sound.py
@ -8,9 +8,10 @@ Handles all audio functionality including:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pyglet
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import pyglet
|
import time
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
from pyglet.window import key
|
from pyglet.window import key
|
||||||
|
|
||||||
@ -235,27 +236,33 @@ class Sound:
|
|||||||
self.stop_all_sounds()
|
self.stop_all_sounds()
|
||||||
if self.currentBgm:
|
if self.currentBgm:
|
||||||
self.currentBgm.pause()
|
self.currentBgm.pause()
|
||||||
|
|
||||||
if soundName not in self.sounds:
|
if soundName not in self.sounds:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create and configure the player
|
# Create and configure the player
|
||||||
player = pyglet.media.Player()
|
player = pyglet.media.Player()
|
||||||
player.queue(self.sounds[soundName])
|
player.queue(self.sounds[soundName])
|
||||||
player.volume = self.sfxVolume * self.masterVolume
|
player.volume = self.sfxVolume * self.masterVolume
|
||||||
|
|
||||||
# Start playback
|
# Start playback
|
||||||
player.play()
|
player.play()
|
||||||
|
|
||||||
# Wait for completion or skip using game's wait_for_completion method
|
# Make sure to give pyglet enough cycles to start playing
|
||||||
|
startTime = time.time()
|
||||||
|
duration = self.sounds[soundName].duration
|
||||||
|
pyglet.clock.tick()
|
||||||
|
|
||||||
|
# Wait for completion or skip
|
||||||
interrupted = self.game.wait_for_completion(
|
interrupted = self.game.wait_for_completion(
|
||||||
lambda: not player.playing
|
lambda: not player.playing or (time.time() - startTime) >= duration
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure cleanup
|
# Ensure cleanup
|
||||||
player.pause()
|
if interrupted:
|
||||||
|
player.pause()
|
||||||
player.delete()
|
player.delete()
|
||||||
|
|
||||||
# Resume background music if it was playing
|
# Resume background music if it was playing
|
||||||
if self.currentBgm:
|
if self.currentBgm:
|
||||||
self.currentBgm.play()
|
self.currentBgm.play()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user