Libgdx 如何让按钮播放声音?
How to make buttons play sound in Libgdx?
如何让 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;
}
});
如何让 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;
}
});