The technique is very similar to that used in the Scratch program.
All that remains is to start the flow of bats. In the Scratch program, we used "when green flag is clicked, create a clone of myself" to get the first one started. Here, we just make a single unconditional call to AddNewBat. Once the first bat occurs, the others will surely follow.
setInterval which we've used before creates a timer that continues firing at regular intervals without you having to do anything.
setTimeout creates a timer that fires one-time only for each time you make the call.
|