I’m trying to render a few hundred tiles (400 to be exact), and for whatever reason, the spritebatch is only drawing about half of them, in the same weird pattern every time. I tried outputting the positions to the console and sure enough, those are all correct. I tried different overloads of the SpriteBatch.Draw method but I get the same results. Here is a screenshot:!
Capture|690x390
Here is the code:
public class TileMap
{
public Vector2[] position;
public int[] type;
public int width, height, size;
public TileMap(int width, int height)
{
position = new Vector2[width * height];
type = new int[width * height];
this.width = width;
this.height = height;
size = width * height;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
position[x * y] = new Vector2(x, y);
Console.WriteLine(x + " " + y);
}
}
}
public void Generate(int seed)
{
}
public void Draw(SpriteBatch spriteBatch)
{
for (int i = 0; i < size; i++)
{
Point position16 = (position[i] * 16).ToPoint();
spriteBatch.Draw(Main.tileTextures[type[i]], new Rectangle(position16, new Point(16, 16)), new Rectangle(0, 0, 16, 16), Color.White);
}
}
}
btw I’m passing 20, 20 into the constructor. If anyone knows what the problem is I would appreciate your feedback.