Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3619118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:50:18+00:00 2026-05-18T22:50:18+00:00

This is an XNA question… I have a large number of objects that are

  • 0

This is an XNA question…

I have a large number of objects that are DrawableGameComponents in my game and they all share the same SpriteBatch. However, I have to call SpriteBatch.Begin() and .End() everytime to draw each component. I want to draw everything in a single batch for better performance but I don’t know where .Begin() and .End() can go since the .Draw() is being automatically called (as they are DrawableGameComponents)

Does anyone know what I can do to make them all be drawn between a single .Begin() and .End() call whilst keeping them as DrawableGameComponents?

Edit:

Alright from this website http://www.progware.org/Blog/post/XNA-Game-Development-(Decentralize).aspx I figured that it’s called at the main game loop’s base.Draw() call… so I can just wrap that with the Begin and End methods

protected override void Draw(GameTime gameTime) {
    if (Cell.Cell.CellSpriteBatch != null) {
        Cell.Cell.CellSpriteBatch.Begin(
            SpriteSortMode.BackToFront, BlendState.AlphaBlend, 
            SamplerState.AnisotropicClamp, null, null, null,
            gamePlay.Camera.GetTransformation()
        );
    }

    base.Draw(gameTime);

    if (Cell.Cell.CellSpriteBatch != null) {
        Cell.Cell.CellSpriteBatch.End();
    }
}

and it works now but doing it this way seems to mean that everything else that I want drawn in a different SpriteBatch will always be drawn below this (as they are drawn first) because the .End() of this SpriteBatch is always going to be called last.

Any solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:50:19+00:00Added an answer on May 18, 2026 at 10:50 pm

    Firstly, unless you already know that you are batch limited its probably not worth doing this. If every single .Draw call is pulling from the same texture then you might see some speed up. If they are different textures then switching to a single Begin/End will have no difference. SpriteBatch will break up your draw calls anyway.

    As you found doing this makes your code pretty confusing too – you have to keep track between components.

    The only solution to your current problem is to make the SpriteBatch Immediate so that it draws as you call the draw calls instead of drawing at the End call. However this will kill your perf as no batching is done at all.

    Personally I would stick to a Begin/End per component until you hit a perf problem. Assuming you don’t have 5000 components that is in which case you probably need to architect things a little differently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a simple xna game that i want to port that to silverlight,
Let’s say that I have two C# applications - game.exe (XNA, needs to support
I have a question about a XNA game I'm making, but it is also
I am working on a game project using Microsoft XNA framework, although this question
This question is a derivative of this one: Creating XNA AudioEngine on windows game
I have a problem with the logic of this code, XNA's Update Method is
First of all, my question isn't really specific to C# or XNA, but my
I have a WinForms application that uses XNA to animate 3D models in a
(The context of this question is specific to XNA, but the principle is general.)
I have a question about degrading performance in XNA. I am using the GameStateManagement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.