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

Allow Volume control of Music & Sound with Property #1310

Open
DeathPhoenix22 opened this issue Oct 24, 2023 · 0 comments
Open

Allow Volume control of Music & Sound with Property #1310

DeathPhoenix22 opened this issue Oct 24, 2023 · 0 comments
Labels
type:new feature Adding a feature that isn't currently present

Comments

@DeathPhoenix22
Copy link
Contributor

Volume manipulation with Property
It's currently possible to change the volume of Music and Sound. The fact that we don't have access to a volume property prevents the use of Timeline effects (FadeIn, FadeOut for example).

Granting access to the Volume property of the native Javafx Audio entity would bypass the current Global Volume implementation. The solution most allow both features to coexist.

Work Around

Music music = getAssetLoader().loadMusic("rain.mp3");
music.getAudio().setVolume(0.0);
DoubleProperty volumeHook = new SimpleDoubleProperty(0.0);
volumeHook.addListener((observableValue, number, t1) -> {
    music.getAudio().setVolume((double)t1);
});
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5), new KeyValue(volumeHook, 1.0)));
FXGL.getAudioPlayer().playMusic(music);
timeline.play();

Real Life Example
To provide additional context, I'm building an RTS. This means that sound may play even though you don't see the source, but it's distance from the Camera affects it's native volume. Also, the closer you are from the source (Zoom level), the higher the volume is. Another aspect of the sound effect system is ambient sound such as Rain. The rain doesn't appear directly from volume 0 to 1. It will fade in and fade out. You can also easily consider that the sound will get heavier the harder the storm is (I also have a Storm system which will require Rain to consider the intensity of the weather).
I should normally also Pan the sound (Left/Right) based on the source location from the player screen, but this part will be left for another PR, if time permits.

CC: @AlmasB @chengenzhao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:new feature Adding a feature that isn't currently present
Projects
None yet
Development

No branches or pull requests

1 participant