问题
I have a question regarding the Libgdx SpriteBatch
:
When I call SpriteBatch#draw()
, will Libgdx take care about the Camera
s frustum or will it draw it, even if it is outside the frustum?
I was allready looking at the SpriteBatch
s code, but I did not find anything, so I was wondering, if Libgdx does something internally.
Or do I have to implement frstum culling myself e.g. like this:
if(camera.frustum.boundsInFrustum(250, 32, 0, 100, 100 ,0)) {
tempEnemy.draw (batch);
}
Where tempEnemy
is a Sprite
, (250,32) is it's center and (100,100) is his half size.
回答1:
If i understand you correctly, you are asking, whether Libgdxs SpriteBatch
takes care about the ViewFrustum
and just draws visible parts or if it just draws everything you tell him to draw.
If thats the question, the answer is, the SpriteBatch
draws everything, ignoring the ViewFrustum
. You have to take care about that yourself, or use Scene2D, which seems to do some culling.
回答2:
this is a comment but to very long, I thought this would be the most comfortable way to read:
in my case I think Tenfour04, is right, It is more efficient without cullig, I will try to describe what may be the reason, in my situation :
-> It may not be less efficient by check of fustrum, but, by the operations you need to perform after
-> 1 in my case using an observer pattern, you see when the camera moves and notifies its current fustrum actors
-> 2 the actors have to look, if her are within range, having to call, getX, getw, ect, more instructions are added process
-> 3 if the actor is inside range, is added to, arraylist which now has the SpriteBatch with Renderable custom interface, more processing load, create the new arrayList if added or actors removed, by Array Class,
Maybe not the best implementation, and there things that could be improved, make a 2d fustrum not use arrayList ect, maybe all that would be more effcient, if you have many sprites in the game but for a few Sprite i think not.
My simple benchmark I did not, even if the fustrum will be used to cancel the update of the actors, because maybe if it would be efficient, for example, exclude many actors with animation, but these players do not move ect.in conclusion,
I think to a simple 2d game with few players is not efficiente in my case, I just wanted to comment, if someone helps
Thank Springrbua, noone and Tenfour04 for all
Note: anyway, my simple game now has a rate of 60, 61 fps without using culling, a simple device, that's very cool haha
来源:https://stackoverflow.com/questions/29916236/spritebatch-draw-all