Workshop › Tower Defense › Step 11 of 42
Enemies arrive one at a time: spawnIn counts down every frame, and when it runs out a new enemy starts at d = 0
with 10 health, and the countdown starts again at 45. toSpawn says how many are still to come.
```js
let toSpawn // enemies still to come in this wave
let spawnIn // frames until the next one
toSpawn = 30
spawnIn = 0
function update() {
if (toSpawn > 0) {
spawnIn -= 1
if (spawnIn <= 0) {
enemies.push({ d: 0, hp: 10 })
toSpawn -= 1
spawnIn = 45
}
}
```spawnIn counts down.spawnIn starts at 0, so the first enemy comes at once.let enemies write let toSpawn and let spawnIn; in reset, under enemies = [], write toSpawn = 30
and spawnIn = 0.update, write the spawning block and an empty line.Skills: Game states, The game loop
← Off the end of the road Towers →