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 9021559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:17:02+00:00 2026-06-16T05:17:02+00:00

What is an efficient way to draw sprites in my 2D XNA game? To

  • 0

What is an efficient way to draw sprites in my 2D XNA game? To be more concrete, I have split this question up into 4 questions.


I used to declare Game1’s spriteBatch static, and called SpriteBatch.Begin and .Close in every IDrawable.Draw. That didn’t work well. Giving each drawable it’s own SpriteBatch also didn’t work well.

Q1: I assume it’s best to have one SpriteBatch instance, and only call begin/close once. Is this correct?


Currently, my Game1.Draw looks something like this:

spriteBatch.Begin();

base.Draw(gameTime); // draws elements of Game.Components

// ...

spriteBatch.End();

Q2: This way, Begin is called only once. Is this the way to go? How did you guys solve this?


Q3: Also, every component has it’s own IGameComponent.LoadContent method. Am I supposed to load my content there? Or is it better to load content at a parent class, such as Game1.LoadContent?


I realise that I should never load the same content twice, so I have given my drawable components both a static and a non-static Texture2D, and gave them 2 constructors:

static Texture2D defaultTexture;
public Texture2D MyTexture;

public Enemy()
    : this(defaultTexture) { }

public Enemy(Texture2D texture)
{
    MyTexture = texture;
}

protected override void LoadContent()
{
    if (MyTexture == null)
    {
        if (defaultTexture == null)
        {
            defaultTexture = Content.Load<Texture2D>("enemy");
        }

        MyTexture = defaultTexture;
    }
}

This way, the default textures of a class are only loaded the first time LoadContent is called on that class. However, when the parameter texture is specified in the constructor, I’ll have to load that texture beforehand.

Q4: I think there should be better ways to do this. I’m thinking of creating a texture dictionary with their asset names as string. What would you suggest?

  • 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-16T05:17:03+00:00Added an answer on June 16, 2026 at 5:17 am

    I used to declare Game1’s spriteBatch static

    You don’t have to have it static. Just make a singleton. Inside Draw method

    SpriteBatch spriteBatch = ScreenManager.SpriteBatch; // singletion SpriteBatch
    spriteBatch.Begin();
    // Draw the background
    spriteBatch.Draw(background, ...
    foreach (var enemy in enemys)
    {
         enemy.Draw(gameTime);
    }
    // etc.
    spriteBatch.End(); // call here end 
    base.Draw(gameTime); // and then call the base class
    

    I assume it’s best to have one SpriteBatch instance, and only call
    begin/close once. Is this correct?

    I advice you to open and end the SpriteBatch within one method. It will help you avoid conflicts with SpriteBatch that started drawing, but didn’t finish.

    Are you adding your elements to the global collection of components? This is a bad idea to add drawable to this collection. You cannot control the order of drawing, the components are global. See this answer.

    Implement in your components IUpdatable and IDrawable and call them in your code where you need it. Get rid of the static stuff and use Dependency Injection istead.

    Also, every component has it’s own IGameComponent.LoadContent method. Am I supposed to load my content there? Or is it better to load content at a parent class, such as Game1.LoadContent?

    You should load assets when you need it and you are responsible for it. You don’y have to load all 30 levels when user just started the game, do you? For example, when your game starts you load all assets that you need for your start screen and main menu. If you load just what you need the player is happy that game starts fast. Then player wants to start the gameplay. Here you can load the assets on a separate thread to keep the app responsive.

    I think there should be better ways to do this. I’m thinking of creating a texture dictionary with their asset names as string. What would you suggest?

    Content.Load is cached already, so you don’t have to do it.

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

Sidebar

Related Questions

What is the most efficient way to get Elastic Map Reduce output into SimpleDB?
Is there a more efficient way to list files from a bucket in Amazon
What is the most efficient way to drop a table in SAS? I have
Is there are more efficient way than the following for selecting the third parent?
Is there efficient way to do this?
I have a SQL efficiency question. This is concerning the Norwegian national lottery. They
What's the efficient way to render a bunch of layered textures? I have some
What is the most efficient way to sort a list, [0,0,1,0,1,1,0] whose elements are
What is the most efficient way for checking for equality of two m *
What is the most efficient way to set/re-order the TabIndex properties of many form

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.