Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow volume control of Music & Sound with property #1311

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

DeathPhoenix22
Copy link
Contributor

@DeathPhoenix22 DeathPhoenix22 commented Oct 24, 2023

Hi,

Issue Link: #1310

Here's an implementation that allow custom Volume configuration of all Sounds & Musics. I've placed the "Master / Global" volume property of the AudioType inside them. This felt pretty natural since the "expert" (GRAPS) of that information is the AudioType itself. This also mean that we could really easily add a new AudioType without much efforts and that new type would automatically mix itself against the Global and the current Audio.

@AlmasB NOTE: I took the initiative to revert the changes made in #1187. Granting access to the internal audio is causing a bug related to volume adjustments in the settings. Whenever a player was adjusting his Global volume, all custom changes made on the audio (getAudio()) was automatically reverted. With this implementation, the conjunction of the 2 values are always kept (via the mix() method)

Example:

Music music = getAssetLoader().loadMusic("rain.mp3");
music.setVolume(0.0);
Timeline timeline = new Timeline(
    new KeyFrame(Duration.seconds(5),
    new KeyValue(music.volumeProperty(), 1.0))
);
FXGL.getAudioPlayer().playMusic(music);
timeline.play();

Note that changing the Global Music volume will also automatically impact all Music:

AudioType.MUSIC.getVolume().set(AudioType.MUSIC.getVolume().get() - 0.1);

I've tested it on my own game and I needed it!
I hope you like it! :)

@Inject("isPauseMusicWhenMinimized")
private var isPauseMusicWhenMinimized = true

private val loader = DesktopAndMobileAudioLoader()

override fun onMainLoopStarting() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically handled by the Audio with Property change listeners

@@ -74,7 +57,6 @@ class AudioPlayer : EngineService() {
if (!activeSounds.containsByIdentity(sound))
activeSounds.add(sound)

sound.audio.setVolume(soundVolume.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need anymore, the global volumes are automatically mixed with the Media configured sound

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant