我正在慢慢学习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/