Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see several problems in your code:</p> <ol> <li>You have <strong>an infinite loop</strong> here in your code. What is the termination condition for your nested loops?</li> <li>(important!) The <code>spriteBatch.Draw()</code> method <strong>doesn't draw anything, it just schedules the drawing of your sprites</strong>. This method invocation should be preceded by <code>spriteBatch.Begin()</code> (to start scheduling he drawing) and eventually you must call <code>spriteBatch.End()</code> to flush the scheduled spites to your device. You infinite loops cause the infinite scheduling of your sprite drawing until the memory is full and you are facing the out of memory exception.</li> <li>(note!) In you condition <code>(x &gt;= 5 | y &gt;= 5)</code> you are using <strong>a bitwise OR</strong> comparison, you shouldn't do it (unless on purpose, which I don't see here and rather use boolean OR: <code>(x &gt;= 5 || y &gt;= 5)</code></li> <li>It is a very bad habit to modify loop counters within the loop itself. Not it is only errors prone, it is also difficult to understand and support your code written this way.</li> </ol> <p>I would re-write your code this way</p> <pre><code> spriteBatch.Begin(); for (int x = 0; x &lt; 5; x++) { for (int y = 0; y &lt; 5; 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); } } spriteBatch.End(); </code></pre> <p>It will re-draw all your tiles on every <code>Draw()</code> event of the main gameloop (provided you are still calling this method from your <code>Draw()</code> method of your <code>Game</code> class. XNA varies the FPS rate depending upon the performance of you PC and the amount of calculation it has to be done on every frame.</p>
 

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