How often to call SpriteBatch.Begin () /. End ()?

I am looking for a performance issue in the Drawing part of my xna code for Windows Phone 7, which sometimes occurs after a few seconds. Is there any best practice how / when to call SpriteBatch.Begin to draw something? Should it be called for each pair of sprites (in each class, when it draws a player, background, background objects, ...) or call at the beginning → draw everything in all subclasses - is it better for performance?

+5
source share
2 answers

You should not use them more than necessary, because Begin () means preparing the device for rendering sprites, and End () means restoring its previous state. This may depend on some flags in Begin () saying that you do not want state changes, and may complicate your code because you will have to manually set some states.

Device state changes are often slow, and you must prevent them, if not required, they can also interfere with something you do, so if you want to display something not in SpriteBatch, you must call End (), but if you are sprites that you should name once for all sprites.

End() , , Flush() End(). , . , End(), - Flush() reset, Begin().

+2

, , - / Draw(), , . , . , , :

  • ,
  • -

- (begin- > end)?

+2

All Articles