如何讓TextButton在鼠標懸停在其上時播放聲音?喜歡的東西:如何讓按鈕在Libgdx中播放聲音?
TextButton play = new TextButton("Play", textButtonStyle);
play.addListener(new ButtonHoverListener() {
@Override
public void doSomething() {
...
}
});
如何讓TextButton在鼠標懸停在其上時播放聲音?喜歡的東西:如何讓按鈕在Libgdx中播放聲音?
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;
}
});
Ohhhh謝謝。我實際上閱讀了鏈接Alexander Mironov發佈並且ClickListener也有這些方法。 – name 2015-01-20 21:13:27
InputListener比ClickListener更通用 – WeMakeSoftware 2015-01-20 21:17:46
private Sound sound;
public void Create() {
sound = Gdx.audio.newSound(Gdx.files.internal("damla.mp3"));
}
public void render() {
sesDamla.play();
}
This is summary answer.
看到這個問題:http://stackoverflow.com/questions/23174722/mouse-hover-libgdx](http://stackoverflow .com/questions/23174722/mouse-hover-libgdx) – 2015-01-20 20:42:35
@AlexanderMironov這很有道理。謝謝 – name 2015-01-20 21:13:46