Ok, so I tried executing these 2 pieces of code: (camera is camera=new OrthographicCamera(); camera.setToOrtho(true, 100, 100*screenW/screenH);
, and the 2 texture regions are of size 64*64, from the same textureAtlas)
Code 1: rendering on-screen
public void renderGameScreen(){
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
TextureRegion tr;
for (int i = 0; i<1000; i++){
if (Math.random()>0.5){
tr = R.border;
} else {
tr=R.gamebackground;
}
spriteBatch.draw(tr, (float)(Math.random()*100), (float)(Math.random()*100));
}
spriteBatch.end();
}
Versus code 2: rendering off-screen:
public void renderGameScreen(){
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
TextureRegion tr;
for (int i = 0; i<1000; i++){
if (Math.random()>0.5){
tr = R.border;
} else {
tr=R.gamebackground;
}
spriteBatch.draw(tr, (float)(Math.random()*100)+200, (float)(Math.random()*100)+200);
}
spriteBatch.end();
}
Notice how the two are identical except for the spriteBatch.draw()
method, which in code 2 is offset by 200 pixels, and is therefore off screen)
Result:
On PC, code 1 was at 10 to 30 fps. code 2 was at 50 to 60 fps.
On android code 1 was at 3-4 fps, code 2 was at 60.
So, I'd conclude that yes, libgdx does check if a texture is offscreen before rendering it.
If there are any flaws in my test that may have caused it to give the wrong result, I'd be glad if someone could point them out.
if
check. \$\endgroup\$