Das Problem hatte ich auch und es lag bei mir daran, dass die Index-Variablen anderweitig verwendet und verändert wurden. Versuche, es so zu kapseln:
Code
var counter = 2;
var whichBloons = [1, 2];
var bloonCounter = [5, 3];
var timeLapse = [0, 1];
var intv = 3000;
(function () {
var idx1 = 0, idx2 = 0;
function startCreate() {
var idx2 = 0;
setTimeout(function () {
// hier den ersten Bloon entspr. idx1 erzeugen
console.log("create bloon " + whichBloons[idx1] + " " + Date.now());
idx2++;
var timer = setInterval(function () {
// hier den naechsten Bloon entspr. idx1 erzeugen
console.log("create bloon " + whichBloons[idx1] + " " + Date.now());
idx2++;
if (idx2 == bloonCounter[idx1]) {
clearInterval(timer);
idx1++;
if (idx1 < counter) startCreate()
else console.log("finished, next level");
}
}, intv);
}, timeLapse[idx1] * 1000);
}
startCreate();
})();
Alles anzeigen