I am haveing trouble with the reset command


#1
function spawnEnemy(){

if (game.time.now > enemyTime){
    enemyTime = game.time.now + 3000;
    nombre = Math.floor(Math.random()*3);
    hauteurEnemie = (500 - (nombre + 3)*50);
    hauteurEnemie = Math.floor(Math.random()*hauteurEnemie);
    enemy = enemies.getFirstExists(false)
    if (enemy){
        for (var h = 0; h < nombre + 3; h++)
        {
            enemy.reset(801, hauteurEnemie + h*50);
           
            enemy.body.velocity.x = -75;
        }
    }
}

}

I don’t understand why the function only spawns one ship at a time


#2

That’s resetting the same sprite several times.

Probably you want to move enemy = enemies.getFirstExists(false) etc. into the loop.


#3

Thank you!