我想在C#中绘制瓷砖地图,我遇到的问题在我看来很奇怪。OutOfMemoryException当试图绘制瓷砖地图
我有这个int数组,用于保存x坐标和y坐标以在屏幕上绘制切片。 (不仅0中的箭头为X,另一条是Y)
这是我如何使用循环来渲染瓦到屏幕的一部分,它在这里我发现了一个“ OutOfMemoryException异常”上线,我会注释掉:
public void DrawTest(SpriteBatch spriteBatch)
{
for (int x = 0;; x++)
{
for (int y = 0;; y++)
{
x = level1[x, 0];
y = level1[0, y];
//This line bellow is where it says OutOfMemoryException
spriteBatch.Draw(tileSheet, new Rectangle(x, y, 32, 32), new Rectangle(0, 0, 32, 32), Color.White);
if (x >= 5 | y >= 5)
{
x = 0;
y = 0;
}
}
}
}
当我想打电话给该渲染方法我做它的主类Render方法
levelLoader.DrawTest(this.spriteBatch);
它的工作完美我用这个DrawTest前方法ry画瓦片。但我完全不知道为什么这不能正常工作。
UPDATE:
public void DrawTest(SpriteBatch spriteBatch)
{
for (int x = 0; x < 5 ; x++)
{
for (int y = 0; y < 5 ; y++)
{
x = level1[x, 0];
y = level1[0, y];
spriteBatch.Draw(tileSheet, new Rectangle(x, y, 32, 32), new Rectangle(0, 0, 32, 32), Color.White);
}
}
}
UPDATE2:
public void DrawTest(SpriteBatch spriteBatch)
{
for (int x = 0; x < 5 ; x++)
{
for (int y = 0; y < 5 ; y++)
{
int tileXCord = level1[x, 0];
int tileYCord = level1[0, y];
spriteBatch.Draw(tileSheet, new Rectangle(tileXCord, tileYCord, 32, 32), new Rectangle(0, 0, 32, 32), Color.White);
}
}
}
您可能已尝试批量处理无限数量的绘制调用。你想用这个奇怪的循环做什么? – harold
林试图创建一个类,将绘制游戏的地图即时制作.. – Rakso