You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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
The text was updated successfully, but these errors were encountered: