diff --git a/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/assets/AssetStore.kt b/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/assets/AssetStore.kt index e3da349..a2d2f97 100644 --- a/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/assets/AssetStore.kt +++ b/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/assets/AssetStore.kt @@ -160,10 +160,13 @@ class AssetStore { } assetConfig.sounds.forEach { sound -> - val soundFile = resourcesVfs[assetConfig.folder + "/" + sound.value].readMusic() - val soundChannel = soundFile.decode().toWav().readMusic().play() // -- convert to WAV -// val soundChannel = soundFile.play() -// val soundChannel = resourcesVfs[assetConfig.assetFolderName + "/" + sound.value].readSound().play() + val soundFile = resourcesVfs[assetConfig.folder + "/" + sound.value] .readSound( //readMusic( + props = AudioDecodingProps(exactTimings = true), + streaming = true + ) +// val soundChannel = soundFile.decode().toWav().readMusic().play() // -- convert to WAV + val soundChannel = soundFile.play() +// val soundChannel2 = resourcesVfs[assetConfig.folder + "/" + sound.value].readSound().play() soundChannel.pause() sounds[sound.key] = Pair(type, soundChannel) diff --git a/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/systems/SoundSystem.kt b/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/systems/SoundSystem.kt index 04aa589..6751fc3 100644 --- a/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/systems/SoundSystem.kt +++ b/korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/systems/SoundSystem.kt @@ -53,15 +53,18 @@ class SoundSystem : IteratingSystem( val soundChannel = assetStore.getSound(soundComponent.name) - // Sound enabling/disabling triggered from outside if (soundEnabled == soundEnabledNext) { + // Sound enabling/disabling triggered from outside + soundEnabledNext = !soundEnabled if (soundEnabled) { // if (soundComponent.isPlaying && soundChannel.paused) soundChannel.resume() if (soundComponent.isPlaying) { // soundChannel.current = 10000.milliseconds +// soundChannel.reset() + soundChannel.current = soundComponent.position.milliseconds soundChannel.resume() - println("SoundSystem: Resume sound '${soundComponent.name}'") + println("SoundSystem: Resume sound '${soundComponent.name}' at position '${soundComponent.position}'") } } else { // if(!soundChannel.paused) soundChannel.pause() @@ -86,8 +89,8 @@ class SoundSystem : IteratingSystem( } } - // continuously save the play position - soundComponent.position = soundChannel.current.milliseconds + // continuously save the play position only when game is running - otherwise we overwrite the sound position + if (soundEnabled) soundComponent.position = soundChannel.current.milliseconds // getOrNull(entity)?.let { channel -> // sound.position = channel.current.milliseconds