What is a more economical way of tiling a texture?
I am developing a tile based 2d game. I have split things up into components such as skybackground, landbackground, town, UI and so on, with each component handling its drawing. before invoking any of the draw calls, I spritebatch.Begin()
with default values so that I draw everything in 1 batch.
For drawing the land mass, I repeatedly draw a square land texture across the area until i fill it up. However there is a spriteBatch
mode called linear wrap
that does just that. the downside would be that I will have to change my design by splitting up my one global spritebatch.begin()
many times down to each component.
So my question is what is better/more economical, tiling a texture manually or splitting up the begin()
and end()
among subcomponents?
There are also other issues that may require me to split a single spriteBatch.Begin()
, so how significant is 1 extra spriteBatch.Begin()
? or 10 more? or 100 more? I would like to know at what scale should I start to worry about adding more b开发者_JAVA技巧egins()
.
The best solution is to have as much work happening on the GPU instead of the CPU (e.g. by taking advantage of tiling and the like) and to have as few SpriteBatch.Begin() calls as possible thus...
It's sounds like the optimal solution here is not to go with either extreme.
Why not just have two SpriteBatches and use on for your land and the other for everything else?
e.g. Re-architect your solution so that:
both SpriteBatches are passed into every component and let the component decide which one to use? ...or...
each component has a property that indicate which SpriteBatch it requires and pass in the appropriate one upon drawing?
As for the impact of each SpriteBatch.Begin(), it really depends on your particular game (and the amount of work that needs to happen to complete the previous spriteBatch and begin the next one) so I would suggest continually testing and monitoring performance is your best way to determining when you should care.
精彩评论