From 998e319d92f991994b4935cdc5a940372e088f53 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 23 Feb 2025 21:07:24 -0500 Subject: [PATCH] Fixed cut_scene. --- sound.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sound.py b/sound.py index 931638b..b85b196 100644 --- a/sound.py +++ b/sound.py @@ -8,9 +8,10 @@ Handles all audio functionality including: """ import os +import pyglet import random import re -import pyglet +import time from os.path import isfile, join from pyglet.window import key @@ -235,27 +236,33 @@ class Sound: self.stop_all_sounds() if self.currentBgm: self.currentBgm.pause() - + if soundName not in self.sounds: return - + # Create and configure the player player = pyglet.media.Player() player.queue(self.sounds[soundName]) player.volume = self.sfxVolume * self.masterVolume - + # Start playback 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( - lambda: not player.playing + lambda: not player.playing or (time.time() - startTime) >= duration ) - + # Ensure cleanup - player.pause() + if interrupted: + player.pause() player.delete() - + # Resume background music if it was playing if self.currentBgm: self.currentBgm.play()