I recently started using LibGDX and I am wondering if I have to optimize my code when drawing textures/sprites off-screen, just like I used to do with XNA.
My biggest concern here is specifically for the TiledMapRenderer.render()
method, which draws a tiled map, imported from the Tiled map editor
software.
I don't know how reliable this test I tried was (I just used the Sprite
and SpriteBatch
class here), but here it is:
// Doesn't cause frame drop
spriteBatch.begin();
for (int i = 0; i < 50000; i++) {
mySprite.setPosition(i, i); // most of times this is off-screen
mySprite.draw(spriteBatch);
}
spriteBatch.end()
// Less than 1 frame per second
spriteBatch.begin();
for (int i = 0; i < 50000; i++) {
mySprite.setPosition(0, 0); // always inside the screen view
mySprite.draw(spriteBatch);
}
spriteBatch.end();
So, from what I observe, I assume that anything drawn outside of the screen with LibGDX is not being drawn, to improve performance. Is this the case ? If so, in what degree should I be abusing this feature ?
Is LibGDX just checking a couple of logical conditions with the camera/viewport I am using and the u,v coordinates I am trying to draw the texture to and determines if this texture should or should not be drawn ? Or is it a process that takes requires lot of resources from the system ? Keep in mind that I mostly care about the android devices.
Should I be worried about this at all ? Again, TiledMapRenderer.render()
is my biggest concern here, but I would also like to know if there is an optimization with drawing textures off-screen in general as well.