ibb671 Posted April 26, 2016 Share Posted April 26, 2016 Hello I was hoping someone can help me. In my code I was able to generate a random number of enemies (randomEnemyNumber) from 1-4 with the number of enemies set to 0 and incrementing by 1 within a timer and its inside the update function. I wanted to kill off the enemies when the the random amount of enemies (randomEnemyNumber) generated equals to the number of enemies on screen. But i noticed randomEnemyNumber will update and the current number of enemies will keep incrementing and will not equal. Below is my current code that i have to try and fix it, but I wanted to ask if there is a better way to approach it? Thank you guys again in advance for taking the time. this.enemy++; console.log(this.enemy + "This is the current number of enemies"); var randomEnemyNumber = this.game.rnd.integerInRange(1,4); console.log(randomEnemyNumber + "Current random enemy number"); if(this.enemy==randomEnemyNumber && this.enemy<6){ this.enemy=0; this.enemyGroup.forEachAlive(function(element){ this.tweenFunction(element);//A tween that will kill the enemy onComplete },this); }else if(this.enemy>5){ this.enemy=0; this.enemyGroup.forEachAlive(function(element){ this.tweenFunction(element);//A tween that will kill the enemy onComplete },this); } Below is the screen shot of console.log. Link to comment Share on other sites More sharing options...
Recommended Posts