I made simple tetris game, and it works good on PC, but i want to port it for android, and it lags too much. I found that problem is because of way how I draw Grid, is there a way to optimize it?
Here is function to draw grid:
private void DrawGrid(int rows, int cols, int addedX, int addedY)
{
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= cols; j++)
DrawRectangle(_spriteBatch, new Rectangle(j * cellSize + addedX,
i * cellSize + addedY, cellSize, cellSize), GameShared.Settings.BlackTheme ? Color.Gray : Color.Black, 2);
}
}
Draw Rectangle:
private void DrawRectangle(SpriteBatch spriteBatch, Rectangle rectangle, Color color, int lineWidth)
{
Texture2D _pointTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1);
_pointTexture.SetData<Color>(new Color[] { Color.White });
spriteBatch.Draw(_pointTexture, new Rectangle(rectangle.X, rectangle.Y, lineWidth, rectangle.Height + lineWidth), color);
spriteBatch.Draw(_pointTexture, new Rectangle(rectangle.X, rectangle.Y, rectangle.Width + lineWidth, lineWidth), color);
spriteBatch.Draw(_pointTexture, new Rectangle(rectangle.X + rectangle.Width, rectangle.Y, lineWidth, rectangle.Height + lineWidth), color);
spriteBatch.Draw(_pointTexture, new Rectangle(rectangle.X, rectangle.Y + rectangle.Height, rectangle.Width + lineWidth, lineWidth), color);
}