Hello all, I have the following code bellow. Why dont each of my tiles get different colors?
When I start debugging, all my tiles gets the same colors…
I know it flashes since im drawing all the time, and each flash it changes color.
It seems to be getting one of the spriteBatch.Drawing() method, then draws all tiles, and when its done, it randomly get a new spriteBatch.Drawing() method and draw that untill the end… I want each tiles with random colors!
I hope you guys understood me, if not ill try explain better. I know my code isent good, im just trying dfferent sorts of things
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
// TODO: Add your drawing code here
for (int y = 0; y < screenHeight; y += 32)
{
for (int x = 0; x < screenWidth; x += 32)
{
drawTexture(x, y);
}
}
base.Draw(gameTime);
}
public void drawTexture(int x, int y)
{
spriteBatch.Begin();
Random rand = new Random();
int randomNum = rand.Next(0, 3);
if (randomNum == 0)
{
spriteBatch.Draw(text, new Vector2(x, y), textSourceRectangle, Color.LightBlue, 0.0F, new Vector2(0, 0), 1.0F, SpriteEffects.None, 0.0F);
}
else if(randomNum == 1)
{
spriteBatch.Draw(text, new Vector2(x, y), textSourceRectangle, Color.LightGreen, 0.0F, new Vector2(0, 0), 1.0F, SpriteEffects.None, 0.0F);
}
else
{
spriteBatch.Draw(text, new Vector2(x, y), textSourceRectangle, Color.LightPink, 0.0F, new Vector2(0, 0), 1.0F, SpriteEffects.None, 0.0F);
}
spriteBatch.End();
}