I mean, I want to make a tiled map using scene2d, so in the render method of my game...

public void render(float delta) {
    Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1f);

    gameStage.getCamera().position.set(player.getX(), player.getY(), 0);
    for(int i=0;i<20;i++)
        for(int j=0;j<20;j++)

Does scene2d know if the tile is out of the screen view, so it does not draw it, or do I have to implement code to fix it?

Sorry for my English.


Scene2D already checks if an Actor is on your viewport or not. You don´t need to code that.

Edit: I´m searching on the Scene2D documentation about this, I can´t find it, but I know it is true, if someone can help me and link it, that would be nice :) I think it is necessary to add a reference to the documentation for this answer.

  • 1
    \$\begingroup\$ I think you're referring to the cull-check done? The Group class that is used by the Stage checks each Actor against the culling area before drawing them in the protected void drawChildren (Batch batch, float parentAlpha) method. \$\endgroup\$ – bornander Jan 11 '16 at 9:03
  • \$\begingroup\$ Exactly, this explains it well, thank you. Still did not find this information on the Scene2D wiki though. \$\endgroup\$ – Mayuso Jan 11 '16 at 10:32

Yes, it does.

But in case you want to be sure, you can check it yourself using Frustrum to compare performances.

(If using Frustrum increases performance, then it Scene2D does not check if an actor is on screen or not, renders everything, but this won´t happen).


  • \$\begingroup\$ Well, I guess you can always double check. But yes, performance won´t increase as Frustum does exactly this (check if object is inside the viewport). \$\endgroup\$ – Mayuso Jan 14 '16 at 22:30

Like the two other answers has said it does know when an Actor is outside its culling area.

However your tile is a Texture - not an Actor! Textures will not be automatically culled when drawn outside of the screen. You're also using a SpriteBatch to draw the tile, not a Stage. SpriteBatches does not have any built-in culling either.

So in conclusion your tile map will not be automatically culled when outside of the viewport area. This can, however, be implemented however using the built-in ScissorStack class as long as you remember to do it every time you move your camera.

Rectangle out = new Rectangle(); // Will be assigned by the function call
float viewportWidth = camera.viewportWidth;
float viewportHeight = camera.viewportHeight;
float viewportX = camera.position.x - viewportWidth /2f;
float viewportY = camera.position.y - viewportHeight /2f;

                               viewportX, viewportY, 
                               viewportWidth, viewportHeight, 
                               new Rectangle(0, 0, viewportWidth, viewportHeight), 

ScissorStack.pushScissors(out); // Activate culling

// If you need to reset the culling you have to remove it first

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.