简体   繁体   中英

libGDX - how to remove existing spritebatch on screen?

So I've been looking through and experimenting some stuff but can't quite get how to remove pre-existing spriteBatch on screen.

so basically I have initiated

batcher.begin();
(blah blah blah)
AssetLoader.font.draw(batcher, "Hey guys", x, y);

something like this... now I wish to delete/remove/undraw this thing on screen... how do I do that without using if statement because.. if I start using If statements everything is going to get sooo messy.

Thanks so much!

Its generally accepted practice in an OpenGL application to clear the screen every time and re-draw the entire screen.

So, to "erase" something, you just stop drawing it.

boolean wantToSeeThis = true;

...

void render() {
   batcher.begin();
   (blah blah blah)
   if (wantToSeeThis) {
       AssetLoader.font.draw(batcher, "Hey guys", x, y);
   }
}

void hideIt() {
   wantToSeeThis = false;
}

It is a bit unclear what you are asking. By default your screen gets cleared every frame with this line in the Render method.

gl.glClear( GL20.GL_COLOR_BUFFER_BIT );

Then obviously we need statements of when we want to draw things. If you code your whole program in a single class this obviously gets messy quick. But Java is OOP which means you can add a classes with there own Draw / Render method and there own statements as to when they should be drawn. I suggest you start learning the basics of OOP .

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.

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