Note that there are some explanatory texts on larger screens.

plurals
  1. POCanvas game increase enemies spawn
    text
    copied!<p>I have a game I am making: <a href="http://www.taffatech.com/DarkOrbit.html" rel="nofollow">http://www.taffatech.com/DarkOrbit.html</a></p> <p>What I want to be able to do is when I kill a certain amount of enemies it will level up. This part is working, however I also want the spawn amount to increase when you level up.</p> <p>In my loop function:</p> <pre><code>function Loop() { if (isPlaying == true) { updateLevel(); //this updates the level but it calls it every frame which might be bad. Player1.draw(); drawAllEnemies(); updateStats(); requestAnimFrame(Loop); } </code></pre> <p>The update level function:</p> <pre><code>function updateLevel() { if(Player1.enemiesKilled &lt;3) { level = 1; } else if(Player1.enemiesKilled &gt; 3 &amp;&amp; Player1.enemiesKilled &lt;= 9) { level = 2; } else if(Player1.enemiesKilled &gt; 9 &amp;&amp; Player1.enemiesKilled &lt;=18) { level = 3; } else if(Player1.enemiesKilled &gt; 18 &amp;&amp; Player1.enemiesKilled &lt;= 38) { level = 4; } else if(Player1.enemiesKilled &gt; 38 &amp;&amp; Player1.enemiesKilled &lt;= 70) { level = 5; s } else if (Player1.enemiesKilled &gt; 120) { level = 6; } if(level == 1) { spawnAmount = 1; } else if(level == 2) { spawnAmount = 2; } else if(level == 3) { spawnAmount = 3; } else if(level == 4) { spawnAmount = 4; } else if(level == 5) { spawnAmount = 5; } else if(level == 6) { spawnAmount = 6; } } </code></pre> <p>spawn enemy function:</p> <pre><code>function spawnEnemy(number) //total enemies starts at 0 and every-time you add to array { for (var x = 0; x &lt; number; x++) { enemies[enemies.length] = new Enemy(); } } </code></pre> <p>My init:</p> <pre><code>function init() { spawnEnemy(spawnAmount); drawMenu(); sndIntro.play(); document.addEventListener('click', mouseClicked ,false); } </code></pre> <p>I tried adding: spawnEnemy(spawnAmount); to after I change the spawn amount global var in the updateLevel function but as this gets called every frame it makes hundreds of enemies fly at me. How can I solve this problem?</p> <p>If I try something like this hundreds of enemies are genrated, I assume because it gets called every frame:</p> <pre><code>if(level == 1) { spawnAmount = 1; spawnEnemy(spawnAmount); } </code></pre>
 

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