'Issue with code of animated car driving on road
My code is supposed to use the mouse coordinates to draw a road when the mouse is clicked. Then, a car will drive continuously on it. The issue with my code is that the delay to have the car move on the road does not work properly. This piece of code:
var startTime = parseInt(new Date().getTime())
while (parseInt(new Date().getTime()) - startTime < 5000) {
print("waiting...")
}
drawCar(points[i][0],points[i][1])
is supposed to add a delay between the movements of the car so that the car movement can be visible to the user. The issue is that running the code will crash the page. I have already tried setTimeout() but this does not work properly for my needs. This function successfully adds a delay at the first time it is run but does not add a delay afterwards.
Code: https://editor.p5js.org/emanuele.saladini/sketches/SgcNhZjQS
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
