Question

I am developing a little game using libgdx. It is a 2d top down game with some big maps and many objects on them. So i just want to render things in my view frustum. I have seen the camera.frustum.***inFrustum(Paramter... p). But i am using scene2d and i set up the camera in the Stage, set the SpriteBatchs projection matrix to camera.combined and my Actors draw themself in the overridden draw(SpriteBatch batch) method. How can i access the camera or the view frustum there? Is there a way to get that out of the spritebatch? Or is there another way to realise fiew frustum culling?

Was it helpful?

Solution

You do not need to do this yourself. If you are using a Stage with a camera it automatically just draw the actors that are inside of the view.

If you want to access the camera from the Stage simply get it from the stage. stage.getCamera()

Here is how you get the frustum from an camera inside of an stage:

Camera cam = this.stage.getCamera();
Frustum f = cam.frustum;
float h = cam.viewportHeight;
float w = cam.viewportWidth;
Matrix4 m = cam.combined; //combind projection matrix
Matrix4 m2= cam.projection; 
... 
...

From the camera you can get every projection matrix you need an so on...

Inside of an actor you can get the stage and of the stage you can get everything shown above..

actor.getStage().getCamera().frustum;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top