java - 渲染循环条件 LIBGDX

标签 java loops libgdx render conditional-statements

我正在慢慢学习java/LIBGDX,我有以下方法可以在单击时将图像从黑/白更改为黑色/白色,然后我调用touchGem方法在渲染内。

我遇到的困难是在渲染中调用此方法设置一个条件,以便在创建新的黑色或白色 gem 后停止渲染(正如您现在毫无疑问地知道的那样,一旦单击它就会渲染图像一遍又一遍。)

public void touchGem() {

    Gdx.input.setInputProcessor(stage);

    if (touchGemStatus1 < 1) {
        touchGem1 = new Image(touchGemTextureWhite);
        touchGem1.setColor(1, 1, 1, 1);
        touchGem1.setSize(95, 95);
        touchGem1.setPosition(5, 0);
        touchGem1.addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y,
                    int pointer, int button) {
                return true;
            }

            public void touchUp(InputEvent event, float x, float y,
                    int pointer, int button) {
                if (touchGemStatus1 < 1) {
                    touchGemStatus1 = touchGemStatus1 + 1;

                } else {
                    touchGemStatus1 = touchGemStatus1 - 1;
                }
            }
        });
    } else {
        touchGem1 = new Image(touchGemTextureBlack);
        touchGem1.setColor(1, 1, 1, 1);
        touchGem1.setSize(95, 95);
        touchGem1.setPosition(5, 0);
        touchGem1.addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y,
                    int pointer, int button) {
                return true;
            }

            public void touchUp(InputEvent event, float x, float y,
                    int pointer, int button) {
                if (touchGemStatus1 < 1) {
                    touchGemStatus1 = touchGemStatus1 + 1;

                } else {
                    touchGemStatus1 = touchGemStatus1 - 1;

                }
            }
        });

    }
}

最佳答案

如果 render() 方法仅调用 touchGem(),则它根本不会渲染任何内容。要绘制 touchGem1,您的 render() 方法应如下所示:

    @Override
public void render(float deltaTime) {

    deltaTime = Gdx.graphics.getDeltaTime();

    touchGem();

    batch.begin();
    stage.addActor(touchGem1);
    batch.end();
    stage.act(deltaTime);
    stage.draw();

}

关于java - 渲染循环条件 LIBGDX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23384184/

相关文章:

javascript - 如何使用仅在运行时已知的变量名调用 JavaScript 函数?

parameters - libGdx 构造函数崩溃参数 : Color

libgdx - libgdx 中的文本缩放和定位

java - 平滑移动 LibGdx

MySQL不接受循环结束指令

java - 自动生成 MongoDB 的 Spring 数据查询 : X most recent entries

java - CXF 生成的 WSDL 不包含 WS-SecurityPolicy 定义

java - 将高度转换为英寸 (Java)

c++ - 如何迭代 C++ 字符串 vector ?

java命令行flyway迁移