I create animations, they are time-bound. One follows the other. I need a completely different animation to start at the moment of one animation, which is not related to the first one, and the first cycle of animations waits for the end of the second cycle and only then continues to work further.
I decided to implement this through a recursive set of Timers, but the problem is that the first animation cycle rejects the second animation cycle and prevents the second cycle from completing correctly. That is, they work out of sync. How can I make the first cycle wait for the second one to end?
var func = function(i){
return function(){
if (i >= 5) return;
console.log("turn no. " + i);
// running second recursion
var func2 = function(i_){
return function(){
if (i_ >= 75) return;
console.log("turn no2. " + i_);
if(i_ >= 75) {
console.log('2 Player won');
} else {
setTimeout(func2(++i), 2000);
}
}
}
setTimeout(func2(0), 2000);
// end running second recursion
if(i >= 5) {
console.log('1 Player won');
} else {
setTimeout(func(++i), 100);
}
}
}
setTimeout(func(0), 100);
thanks a lot in advance)
desired final output:
turn no. 0
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
turn no. 1
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
turn no. 2
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
turn no. 3
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
turn no. 4
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
turn no. 5
turn no2. 0
turn no2. 1
turn no2. 2
turn no2. 3
turn no2. 4
turn no2. 5
2 Player won
1 Player won
p.s. what i want is it generally possible?)))
p.s.s i just need to somehow do two related animations with time dependency