[英]Libgdx Draw Texture constantly
When my if-statement is true, I want to draw a Texture.当我的 if 语句为真时,我想绘制一个纹理。
But the Texture is displayed for a second and directly disposes.但是Texture显示一秒直接dispose。
I wanted to ask if there is a way to stop the disposing and display the Texture even after the condition is fulfilled.我想问是否有办法在满足条件后停止处理并显示纹理。
my render method:我的渲染方法:
@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();
}
}
EDIT: clarified my question and added more code编辑:澄清了我的问题并添加了更多代码
In case i understand your question correctly you shouldnt be rendering an object by checking collisions.如果我正确理解您的问题,您不应该通过检查碰撞来渲染 object。 Instead render from arrays of your game entities.
而是从游戏实体的 arrays 渲染。
update object positions更新 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
Hope this helps.希望这可以帮助。
Regards问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.