Note that there are some explanatory texts on larger screens.

plurals
  1. POOutOfMemoryException when trying to draw tile map
    primarykey
    data
    text
    <p>I'm trying to draw a tile map in C# and the problem I'm having is strange in my opinion. </p> <p>I have this int array that is suposed to hold the x coordinate and y coordinate to draw the tiles on the screen. (The arrow with not only 0's in it is X and other one is Y)</p> <pre><code>int[,] level1 = { { 0, 32, 64, 96 }, { 0, 0, 0, 0 } }; </code></pre> <p>Here is how I use for loops to render a part of the tile into the screen and it's here I'm getting an "OutOfMemoryException" on a line that I will comment out:</p> <pre><code>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 &gt;= 5 | y &gt;= 5) { x = 0; y = 0; } } } } </code></pre> <p>When i want to call this render method i do it in the main class Render method </p> <pre><code>levelLoader.DrawTest(this.spriteBatch); </code></pre> <p>It worked perfectly before i used this DrawTest method to try drawing the tiles. But I have completely no idea why this isn't working correctly.</p> <p><strong>UPDATE:</strong></p> <pre><code>public void DrawTest(SpriteBatch spriteBatch) { for (int x = 0; x &lt; 5 ; x++) { for (int y = 0; y &lt; 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); } } } </code></pre> <p><strong>UPDATE2:</strong></p> <pre><code> public void DrawTest(SpriteBatch spriteBatch) { for (int x = 0; x &lt; 5 ; x++) { for (int y = 0; y &lt; 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); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload