//------------------------------
glDegrees = 0;
for (let ii = 0; ii < 10000; ii++) {
glDegrees = ii;
let lCarCenterX = glCarTopLeftX + gcCarImageWidth / 2;
let lCarCenterY = glCarTopLeftY + gcCarImageHeight / 2;
fRender(lCarCenterX, lCarCenterY, glDegrees);
fSleep(1000);
}
//------------------------------
//------------------------------
function fSleep(num) {
let now = new Date();
let stop = now.getTime() + num;
while(true) {
now = new Date();
if(now.getTime() > stop) return;
}
}//fSleep
//------------------------------
The fSleep function blocks the fRender function thread from continuing. Is there an asynchronous function that does not block the fRender thread from continuing?
That’s kind of the point of a sleep function - to ensure smooth behavior and allow enough time for something to respond. If you don’t want it to actually sleep, just take it out…
DaveMaxwell, The fRender needs time to complete it’s task. The fSleep function, which delays properly, consumes CPU time => the fRender thread is stopped, and never changes the display until the very end.
End result: The car jumps from a horizontal position to the end angle position. The angles in-between are never displayed.