When my if-statement is true, I want to draw a Texture.
But the Texture is displayed for a second and directly disposes.
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. Instead render from arrays of your game entities.
update object positions
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.