Update: I figured out it has nothing to do with the camera but instead framerate drops when drawing my map tiles onto the screen.
Here’s a link to a video showcasing the bug in action (For further reference): https://streamable.com/m4zuf3
Any and all guidance is appreciated, thanks.
Here's the draw functions:
protected override void Draw(GameTime gameTime)
{
m_mainLevel.Draw(spriteBatch);
}
public void Draw(SpriteBatch sb)
{
//Draw Background
for (var i = 0; i < BackgroundTiles.Length; i++)
{
int id = BackgroundTiles[i].m_id;
int column = id % TilesetTilesWide;
int row = (int)Math.Floor((double)id / (double)TilesetTilesWide);
int width = Map.TileWidth * 2;
int height = Map.TileWidth * 2;
float x = (i % Map.Width) * width;
float y = (float)Math.Floor(i / (double)Map.Width) * height;
Rectangle tilesetRec = new Rectangle(TileWidth * column, TileHeight * row, TileWidth, TileHeight);
Rectangle dest = new Rectangle((int)x, (int)y, width, height);
sb.Draw(Tileset, dest, tilesetRec, Color.White);
}
}
Is the problem that I'm drawing too many tiles per frame? the map size is 250 x 250 tiles, with each tile being 16x16px.