title: Best practices: efficient sprite drawing in XNA
body: <p>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.</p>
  
  <hr>
  
  <p>I used to declare Game1's spriteBatch <strong>static</strong>, and called <code>SpriteBatch.Begin</code> and <code>.Close</code> in every <code>IDrawable.Draw</code>. That didn't work well. Giving each drawable it's own SpriteBatch also didn't work well.</p>
  
  <p><strong>Q1</strong>: I assume it's best to have <strong>one</strong> SpriteBatch instance, and only call begin/close <strong>once</strong>. Is this correct?</p>
  
  <hr>
  
  <p>Currently, my <code>Game1.Draw</code> looks something like this:</p>
  
  <pre><code>spriteBatch.Begin();
  
  base.Draw(gameTime); // draws elements of Game.Components
  
  // ...
  
  spriteBatch.End();
  </code></pre>
  
  <p><strong>Q2</strong>: This way, <code>Begin</code> is called only once. Is this the way to go? How did you guys solve this?</p>
  
  <hr>
  
  <p><strong>Q3</strong>: Also, every component has it's own <code>IGameComponent.LoadContent</code> method. Am I supposed to load my content there? Or is it better to load content at a parent class, such as <code>Game1.LoadContent</code>?</p>
  
  <hr>
  
  <p>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 <code>Texture2D</code>, and gave them 2 constructors:</p>
  
  <pre><code>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&lt;Texture2D&gt;("enemy");
          }
  
          MyTexture = defaultTexture;
      }
  }
  </code></pre>
  
  <p>This way, the default textures of a class are only loaded the first time <code>LoadContent</code> is called on that class. However, when the parameter <code>texture</code> is specified in the constructor, I'll have to load that texture beforehand.</p>
  
  <p><strong>Q4</strong>: 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?</p>