我正在 XNA 中创建一个需要绘制数千个小矩形/正方形的游戏。随着数量的增加,性能会变得更差。这是我当前使用的代码:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
foreach (SandBit sandBit in sandBitManager.grid)
{
Point p = sandBit.Position;
spriteBatch.Draw(square, new Rectangle(p.X, p.Y, sandBit.SIZE, sandBit.SIZE), Color.White);
}
spriteBatch.End();
base.Draw(gameTime);
}
我要求spriteBatch.Draw()
每一个方格,我正在重绘整个屏幕只是为了添加一个方格。我已经进行了大量搜索,我相信解决方案是绘制一个纹理,然后调用Draw()
该纹理,但我找不到相关示例。