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

How to switch bgm smoothly #1289

Closed
loveqianqian413 opened this issue Aug 29, 2023 · 2 comments
Closed

How to switch bgm smoothly #1289

loveqianqian413 opened this issue Aug 29, 2023 · 2 comments
Labels
type:new feature Adding a feature that isn't currently present

Comments

@loveqianqian413
Copy link

add more api

@loveqianqian413 loveqianqian413 added the type:new feature Adding a feature that isn't currently present label Aug 29, 2023
@chengenzhao
Copy link
Contributor

chengenzhao commented Sep 6, 2023

Hi:

Current version allow developers to control the Music separately
so you may use an animation to fade out current music
and also fade in another music with another animation
ParallelAnimation could combine two animations together
e.g.

fade in

    var bgm = FXGL.loopBGM("maou_game_theme01.mp3");
    bgm.getAudio().setVolume(0);
    new Transition() {
      {
        setCycleDuration(Duration.seconds(1));
      }

      protected void interpolate(double frac) {
        bgm.getAudio().setVolume(FXGL.getSettings().getGlobalMusicVolume() * frac);
      }
    }.play();

fade out

    var transition = new Transition() {
      {
        setCycleDuration(Duration.seconds(5));
      }

      protected void interpolate(double frac) {
        bgm.getAudio().setVolume(FXGL.getSettings().getGlobalMusicVolume() * (1 - frac));
      }
    };
    transition.setOnFinished(_1 -> bgm.getAudio().stop());
    transition.play();

cheers

@loveqianqian413
Copy link
Author

that was cool man , tks a lot! : )

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

2 participants