【发布时间】:2016-12-23 06:25:43
【问题描述】:
我创建了一个带有三个可绘制图像的 imageButton; 一种是按钮向上,按钮向下和按钮检查。其目的是为游戏打开和关闭声音。一旦声音关闭,应显示检查图像。
我写的代码是这样的:
soundButton = new ImageButton(new TextureRegionDrawable(soundTexture1),
new TextureRegionDrawable(soundTexture2), new TextureRegionDrawable(soundTexture3));
stage.addActor(soundButton);
soundButton.setPosition(Constants.WORLD_WIDTH / 4 + 300f, Constants.WORLD_HEIGHT / 4, Align.bottomLeft);
soundButton.addListener(new ChangeListener(){
@Override
public void changed(ChangeEvent event, Actor actor) {
if(!game.soundBool)
game.soundBool=true;
else
game.soundBool=false;
}
});
这里 soundBool 最初是假的,当它是假的时候会播放游戏声音。 一旦我做到了,声音就不应该播放了。这个布尔值运行良好。
问题是,一旦我检查了按钮(声音关闭)声音就会永久关闭。再次单击按钮无法按预期工作。
如何更改代码以使其正常工作?
【问题讨论】:
标签: libgdx imagebutton