我想在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