title: C# XNA Draw method and collision bugs
body: <p>I've been trying to make a 2D RPG game after learning C# XNA from a book creating 3 games but these bugs are driving me insane and I'm gonna have to give up as I can not find any fix.</p>
  
  <p>First of all is the Draw method, i have rocks on the screen and i have them drawn at the same depth but drawn in order so it goes along to X axes, then it increments the Y axes and resets X and so on. So they should overlap other rocks above them or to the left but it doesn't work. They randomly go on top of each other when i move around or shoot arrows, here is my code if it helps:</p>
  
  <p>Game1.cs Draw Method</p>
  
  <pre><code>Protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
          spriteBatch.Begin(
              SpriteSortMode.BackToFront,
              BlendState.AlphaBlend);
  
          TileMap.Draw(spriteBatch);
          ObjectManager.Draw(spriteBatch);
          player.Draw(spriteBatch);
          WeaponManager.Draw(spriteBatch);
  
          spriteBatch.End();
  
          base.Draw(gameTime);
      }
  </code></pre>
  
  <p>ObjectManager Draw Method</p>
  
  <pre><code>static public void Draw(SpriteBatch spriteBatch)
      {
          // Get the tile locations of each corner tile on the screen
          int startX = (((int)Camera.Position.X) / 32) - 2;
          int endX = ((int)Camera.Position.X + Camera.ViewPortWidth) / 32;
  
          int startY = (((int)Camera.Position.Y) / 32) - 2;
          int endY = ((int)Camera.Position.Y + Camera.ViewPortHeight) / 32;
  
          // Go through all possible objects and draw them to the screen if they exist
          for (int y = startY; y &lt;= endY; y++)
              for (int x = startX; x &lt;= endX; x++)
              {
                  if ((x &gt; 0) &amp;&amp; (y &gt; 0) &amp;&amp; (x &lt; MapWidth - 1) &amp;&amp; (y &lt; MapHeight - 1))
                  {
                      if (objects[x, y] != null)
                      {
                          spriteBatch.Draw(
                                  texture,
                                  Camera.Transform(objects[x, y].destinationRectangle),
                                  objects[x, y].Frame,
                                  new Color(256, 256, 256, objects[x, y].Transparency),
                                  0,
                                  new Vector2(0, 0),
                                  SpriteEffects.None,
                                  objects[x, y].Depth);
                      }
                  }
              }
      }
  </code></pre>
  
  <p>The second problem is with my collision, I am using bounding box collision with the Rectangle class for everything. When my player character moves, I create a new Rectangle for the new location, and if he is colliding with any of the bounding boxes of any object then movement is cancelled but sometimes he will still move to that location and get stuck in the object by 1 pixel. It just doesn't make any sense how it happens sometimes and other times it doesn't, even with the same object. If anyone has any idea why this could be happening please post, there is way too much code to paste on here so I'll leave it, I'm more bothered about the Draw method problem.</p>