I’m cleaning up a sandbox into proper Classes, I’ve been a bit lazy and it’s time to do some housekeeping.
And I’m sat here wondering; is it better to use only one Sprite Batch and pass it to all other classes for drawing, or is it better (or at least no worse) to creating a new batch in each class.
Common sense is telling me passing the Batch to all classes that need to draw is going to be a lot better, but my common sense has been known to let me down from time to time!
The advice is to have one SpriteBatch instance, and minimise the number of Begin/End calls. This reduces memory usage and improves rendering performance.
How you work your game code around that generic advice depends on what you’re doing.
How you get the SpriteBatch reference to your rendering code is also up to you You can pass it as a parameter, keep a global static or singleton, add it as a Service and get references that way etc. Whatever. I tend to use the Service method FWIW.