首页 > 解决方案 > 我在 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 变得不可见时,按钮并没有变得不可见,它仍然可见且可点击。我究竟做错了什么?我不明白什么?谢谢,麻烦您了!

标签: androidlibgdximagebuttonscene2d

解决方案


推荐阅读