Reputation: 375
I'm having some issues loading multiple tiles to my game. My game world currently has a pixel size of 770x450. I have loaded a single tile at position (0, 330), and wanted to make a loop that copies and loads the tile along the x axis until it reaches (770, 330).
I have been able to make this loop, however upon every loop, the next tile doesn't load, it just moves to the next position, here's the loop:
for (int i = 0; i < 770; i += 31)
{
position = new Vector2(i, 330);
// Some sort of draw method here!
if (i == 744)
{
i = i + 26;
// or here...
position = new Vector2(i, 330);
// or maybe here?
}
}
And if this helps, here's my current Draw()
method:
spriteBatch.Begin();
spriteBatch.Draw(gameTile, position, Color.White);
spriteBatch.End();
Upvotes: 0
Views: 203
Reputation: 19496
You're only drawing the tile once. You can tell because you only have one spriteBatch.Draw()
call. It doesn't do enough to just update the position inside the loop. You have to draw it at each location as well.
public void Draw()
{
spriteBatch.Begin();
for (int i = 0; i < 770; i += 31)
{
position = new Vector2(i, 330);
if (i == 744)
{
i = i + 26;
position = new Vector2(i, 330);
}
spriteBatch.Draw(gameTile, position, Color.White);
}
spriteBatch.End();
}
Of course, you want to avoid all that loopy logic in the Draw()
method. The only way around that is to create a tile for every position you want it drawn at in your Update()
method. Then the Draw()
method could just loop through all of your gameTiles and draw them at their corresponding position.
Upvotes: 2