When and how often should i call Spritebatch.Begin and Spritebatch.End

I think the answer is, “Whatever works best for you and your game.”

For ultimate efficiency, a single call to Begin/End is the way to go. However, this isn’t always practical. Sometimes it just makes more logical sense for the way your code is structured to Begin/End new batches. Sometimes you need to render to a target in the middle of sprite rendering so you can pull off some effect. Sometimes you need to use a different shader for something on a middle layer.

There are a number of legitimate reasons why you might have more, or nested, calls to these methods. You probably don’t want to do one for every single sprite you render (they don’t call it a batch for nothing), but past that, do what makes sense for you.

It probably is worth while to consider the scope of your project and consider what the performance requirements are. While “best possible performance” is a noble goal and all, it’s rarely practical and often leads to a butt ton of work that the final product probably doesn’t require anyway.

Personally I’m a fan of “optimize when necessary, but consider my needs ahead of time”, but you gotta go with your own instincts :slight_smile:

2 Likes