android - 我在 LIGDX 中的 imageButton(scene2d)在达到 if 语句的条件时没有更新(设置为不可见),我做错了什么?
问题描述
我有一个ImageButton
我想在Constants.AD_PLAYED >= 99
. 这是我的代码。
public class ShopScreen extends ScreenAdapter {
private PuzzleGame game;
private Stage stage;
private Table UITable;
public ShopScreen (PuzzleGame game) {
this.game = game;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void show() {
AssetManager am = new AssetManager();
Assets.instance.init(am);
stage = new Stage();
Gdx.input.setInputProcessor(stage);
TextureRegion regionPlayAdButton = Assets.instance.buttonAssets.playAd;
Drawable drawablePlayAdButton = new TextureRegionDrawable(regionPlayAdButton);
drawablePlayAdButton.setMinWidth(Gdx.graphics.getWidth()/9f);
drawablePlayAdButton.setMinHeight(Gdx.graphics.getWidth()/9f);
ImageButton playAdButton = new ImageButton(drawablePlayAdButton);
UITable = new Table();
UITable.add(playAdButton);
UITable.setPosition(Gdx.graphics.getWidth()/6f,Gdx.graphics.getHeight()/1.2f,Align.center);
stage.addActor(UITable);
if(Constants.AD_PLAYED >= 99){
playAdButton.setVisible(false);
}else
playAdButton.setVisible(true);
}
}
当按下 ImageButton 时,播放广告,当广告完成时,玩家将获得 10 个硬币。该代码有效,但是当我达到 100 个硬币或Constants.AD_PLAYED >= 99
我设置 ImageButton 变得不可见时,按钮并没有变得不可见,它仍然可见且可点击。我究竟做错了什么?我不明白什么?谢谢,麻烦您了!
解决方案
推荐阅读
- android - Android Dagger-Hilt 忽略 @Provides 方法
- c - 使用 janet_wrap_array 的正确方法
- javascript - 反应中的 setState 似乎它删除了所有状态内容
- javascript - 添加媒体查询以根据屏幕大小调整日历小部件 css
- c# - 如何使用 VS 代码在控制台应用程序上正确运行 C# 代码?
- sql - Sparklyr:sql 临时错误:参数不可解释为逻辑
- sql - 如何合并 OUTER JOIN 和 UNION 结果?
- locust - 如何将 Locust 工作人员连接到使用 https URL 运行的主服务器?
- c# - 将 C openssl TripleDes 加密转换为 .NET
- python-3.x - 如何选择此按钮并单击它?