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

  • Home
  • SEARCH
  • 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 8639235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:57:03+00:00 2026-06-12T10:57:03+00:00

I am developing an XNA game. This is time I am careful about the

  • 0

I am developing an XNA game. This is time I am careful about the architecture. Til today, I have always implemented my own draw method in this way:

public void Draw(SpriteBatch sb, GameTime gameTime)
{
    sb.Begin();
    // ... to draw ...
    sb.End();
}

I was digging the DrawableGameComponent and saw the Draw method comes in this way:

public void Draw(GameTime gameTime)
{
    // ...
}

First of all, I know that SpriteBatch can collect many Texture2D between Begin and End, so that it can be useful to sort them, or draw with same Effects.

My question is about the performance and the cost of passing the SpriteBatch. At DrawableGameComponent it is possible to call spritebatch of game object if its spritebatch is public.

What is suggested, what should a xna-game programmer do?

Thanks in advice.

  • 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-06-12T10:57:05+00:00Added an answer on June 12, 2026 at 10:57 am

    One of the serious disadvantages of DrawableGameComponent is that you’re locked into its provided method signature. While there’s nothing “wrong”, per se, with DrawableGameComponent, do not think of it as the “one true architecture“. You’re better off thinking of it as an example of a possible architecture.

    If you find yourself needing to pass a SpriteBatch (or anything else) to the draw method of a “game component” – the best way is to pass it as an argument. Anything else is convoluted.

    Obviously this means that you can’t use XNA’s provided GameComponent system, and you have to make your own alternative. But this is almost trivial: At its most basic level, it’s just a list of some base type that has appropriate virtual methods.


    Of course, if you must use GameComponent – or your game is so simple (eg: a prototype) that you don’t really care about the architecture – then you can use basically any method you like to get a SpriteBatch to your draw method. They all have disadvantages.

    Probably the next-most architecturally robust method is to pass your SpriteBatch instance into the constructor of each of your components. This keeps your components decoupled from your game class.

    On the other hand, if you’re throwing architecture to the wind, I’d suggest making your MyGame.spriteBatch field public static. This is the simplest way to allow it to be accessed anywhere. It’s easy to implement and easy to clean up later when/if you need to.


    To answer your question about performance: Anything to do with passing a SpriteBatch around will have almost negligible effect on performance (providing the order of calls to Draw/Begin/End stays the same). Don’t worry about it.

    (If you see SpriteBatch whatever in code, that represents a reference. A reference is a 32-bit value (in a 32-bit program, which all XNA games are). That’s the same size as an int or a float. It’s very small and very cheap to pass around/access/etc.)

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

Sidebar

Related Questions

I am currently developing a C# .net xna game engine. I have been trying
I am developing a game for Windows Phone 7 using XNA, and I have
I'm developing a 2D overhead shooter game using C# and XNA. I have a
A friend and I plan on developing an XNA game. I'm in charge of
I'm developing a game using XNA and C# and was attempting to avoid calling
I'm developing a game in XNA. It would be nice for it to be
I am developing a 2D game in C#/XNA where the sprites/backgrounds/etc are Texture2Ds. I
I'm developing a game with Microsoft XNA. I haven't used any modelling program(even 2d
I'm currently developing a 2D game with C#/XNA. The game's core feature are bullets
I'm developing a simple shooter game in XNA. I'm adding the copy of the

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.