# How to Spawn Enemies in Waves?

**URL:** <https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054>\
**Category:** Phaser 3\
**Created:** [April 23, 2020, 10:23pm UTC](https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054 "2020-04-23T22:23:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pritster5](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pritster5/32/2780_2.png) [@pritster5](https://phaser.discourse.group/u/pritster5)\
**Post date:** [April 23, 2020, 10:23pm UTC](https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054/1 "2020-04-23T22:23:38Z")

</div>

I’ve been struggling with this for a while but how can I spawn groups of enemies in waves?

I initially spawn enemies using this code inside my Game scene’s `create()` method:

```
//Initial spawn of enemies for wave 1
enemyGrunts = this.physics.add.group({
    key: 'enemyGrunt',
    repeat: gruntAmount - 1,
    setXY: { x: 60, y: 0, stepX: 60 }
});
enemyGrunts.children.iterate(function(child){
    child.setVelocity(0, Phaser.Math.FloatBetween(gruntMinSpeed, gruntMaxSpeed));
});

```

I then try to spawn more inside of my `update()` method when the player has “killed” all the grunts in the current wave:

```
update(){
if (gruntAmount === 0){
        if(currentWave === maxWave){ //If we're on wave 3 (max) and gruntAmount is zero, that means the player has defeated all waves
            this.victoryText.visible = true;
            gameOver = true; 
        }
        else{
        currentWave += 1; //Increment the wave amount to make more baddies spawn
        gruntAmount = currentWave * 2
        enemyGrunts.createMultiple({
            repeat: gruntAmount - 1,
            setXY: { x: 60, y: 0, stepX: 60 } 
        })
        enemyGrunts.children.iterate(function(child){
            child.setVelocity(0, Phaser.Math.FloatBetween(gruntMinSpeed, gruntMaxSpeed));
        });
      }
    }
}

```

I also have some colliders that uses the enemyGrunts group to check for collisions with the players bullets and the some other stuff:

```
//Disable the enemy grunts when hit with a antibody
this.physics.add.collider(enemyGrunts, playerBullets, enemyHitCallback, null, this);
//Completely remove the grunts by calling remove() on the child if they touch the player after being antibodied. Also remove them from collision checks.
this.physics.add.overlap(player, enemyGrunts, collectGruntCallback, null, this);
//Disable the grunts when they touch the lungs, then tint the lungs
this.physics.add.collider(enemyGrunts, lungsBG, lungsHitCallback, null, this);

```

**My problem is that the enemyGrunts.createMultiple method isn’t doing anything and I can’t see the newly spawned grunts is it is doing anything at all. What am I doing wrong?**

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [April 23, 2020, 11:14pm UTC](https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054/2 "2020-04-23T23:14:24Z")

</div>

`createMultiple()` needs `{ key }` to create anything.

---

<div class="post-metadata">

**Author:** ![pritster5](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pritster5/32/2780_2.png) [@pritster5](https://phaser.discourse.group/u/pritster5)\
**Post date:** [April 23, 2020, 11:16pm UTC](https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054/3 "2020-04-23T23:16:48Z")

</div>

Wow that was an easy fix. Thanks so much.

---

<div class="post-metadata">

**Author:** ![Radwa4869](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/radwa4869/32/7162_2.png) [@Radwa4869](https://phaser.discourse.group/u/Radwa4869)\
**Post date:** [December 8, 2022, 5:15pm UTC](https://phaser.discourse.group/t/how-to-spawn-enemies-in-waves/6054/4 "2022-12-08T17:15:19Z")

</div>

Hi. 🙂  
can you share the logic of gruntAmount?  
when should it be 0 again?
