gpt4 book ai didi

java - 如何让按钮在 Libgdx 中播放声音?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:45:28 25 4
gpt4 key购买 nike

如何让 TextButton 在鼠标悬停在它上面时播放声音?像这样的东西:

TextButton play = new TextButton("Play", textButtonStyle);
play.addListener(new ButtonHoverListener() {
@Override
public void doSomething() {
...
}
});

最佳答案

play.addListener(new InputListener(){

boolean playing = false;

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
super.enter(event, x, y, pointer, fromActor);
if (!playing) {
Sound sound = Gdx.audio.newSound(Gdx.files.internal("data/mysound.mp3"));
sound.play(1F);
playing = true;
}
}

@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
super.exit(event, x, y, pointer, toActor);
playing = false;
}
});

关于java - 如何让按钮在 Libgdx 中播放声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28054483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com