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

但是纹理会显示一秒钟并直接处理。

我想问问是否有一种方法可以停止处理并即使在满足条件后仍显示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();
        }
    }


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

最佳答案

如果我正确理解了您的问题,则不应通过检查碰撞来渲染对象。而是从游戏实体的数组进行渲染。


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

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 raindropsbatch.end();//update positions


希望这可以帮助。

问候

08-04 14:07