Reputation: 11
I looked a lot in the internet but somehow couldn't find any benefits to always clear the screen in the render method or didn't understand it very well.
So what's the benefit from clearing the screen wouldn't clearing somehow cause the game to draw everything from scratch each time the render method is called?
Upvotes: 0
Views: 133
Reputation: 1160
If you have a game with at least one moving thing, not clearing the screen will cause the sprite (if you're using a sprite) of the thing to be in every place it has been in past frames. Usually you clear the screen to remove past drawn stuff and redraw with updated positions. You could program some logic to know whether stuff has moved and avoid clearing the screen but I don't think clearing the screen's computational cost is high enough for the effort.
Below is an example of the effect caused by not clearing the screen each frame.
Edit: As Tenfour04 stated, there is another good reason for clearing the screen: Perfomance.
Libgdx, like almost all game engines, uses double buffering, which means that while one frame is being rendered to screen, it is already drawing the next frame to another frame buffer. If you don't clear the screen, it has to wait and then copy the contents of the first buffer into the second before it can start drawing to it. So it wastes GPU time copying and also prevents the multitasking that saves some time
Upvotes: 3