Libgdx不断绘制纹理



当if语句为true时,我想绘制一个纹理。

但"纹理"(Texture(会显示一秒钟并直接处置。

我想问是否有一种方法可以停止处理并显示纹理,即使在条件满足后也是如此。

我的渲染方法:

@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(BackgroundImage, 0,0, BackgroundImage.getWidth(), BackgroundImage.getHeight());
batch.end();
// Kamera aktualisiert ihre Matrizen
camera.update();
// Dem SpriteBatch mitteilen , dass es das
// Koordinatedsystem , welches von der Kamera erstellt wurde, benutzen soll
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Rectangle raindrop : raindrops) {
batch.draw(TropfenTexture, raindrop.x, raindrop.y);
}
bmf.setColor(1f, 1f, 1f, 1f);
bmf.draw(batch, ScoreString, 10, 790);
batch.end();
GameSpeedup();
Iterator<Rectangle> iter = raindrops.iterator();
while (iter.hasNext()) {
Rectangle raindrop = iter.next();
raindrop.y -= 200 * Gdx.graphics.getDeltaTime();
if (raindrop.y < 0)
iter.remove();
if (raindrop.overlaps(BoundsBottom)) {
//dropSound.play();
//game.setScreen(new GameOverScreen(game));
//Gdx.input.vibrate(200);
batch.begin();
batch.draw(PfützeTexture, 0, 0);
batch.end();
}
if (Gdx.input.justTouched()) {
Vector3 tmp = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(tmp);
if (raindrop.contains(tmp.x, tmp.y)) {
CurrentScore++;
ScoreString = "" + CurrentScore;
if (dropSound.isPlaying())
dropSound.stop();
dropSound.play();
iter.remove();
if (raindrop.contains(tmp.x, tmp.y) && raindrop.overlaps(BoundsBottom)) {
CurrentScore++;
ScoreString = "" + CurrentScore;
dropSound.pause();
dropSound.play();
iter.remove();
}
}
}
}
if (CurrentScore > Highscore){
Highscore = CurrentScore;
prefs.putInteger("highscore", Highscore);
prefs.flush();
}
}

编辑:澄清了我的问题并添加了更多代码

如果我正确理解你的问题,你不应该通过检查碰撞来呈现对象。相反,从游戏实体的数组中进行渲染。

  1. 检查冲突并根据需要删除添加实体。在你的情况下:去除雨滴,增加飞溅
  2. 渲染对象
  3. 更新对象位置

    if (raindrop.overlaps(BoundsBottom)) { waterRectangles.add(new WaterObject()); //maybe remove raindrop? } batch.start(); for(Rectangle waterObject: waterRectangles{ batch.draw(WaterTexture,waterObject.x,waterObject.y); } //same for raindrops batch.end(); //update positions

希望这能有所帮助。

问候

最新更新