繁体   English   中英

Libgdx 不断绘制纹理

[英]Libgdx Draw Texture constantly

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

但是Texture显示一秒直接dispose。

我想问是否有办法在满足条件后停止处理并显示纹理。

我的渲染方法:

@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();
        }
    }

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

如果我正确理解您的问题,您不应该通过检查碰撞来渲染 object。 而是从游戏实体的 arrays 渲染。

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

    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

希望这可以帮助。

问候

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM