You will need to use setTimeout or setInterval in your solution, but this will not be accurate for the following reasons:
- Browsers have a minimum timeout that is not 0 ms. The minimum browser size is about 14 ms.
- Timers are inaccurate. They represent the time of the queues, not the runtime. If something else executes when your timer fires, your code enters the wait queue and may not be executed until it appears.
You will probably want to use setTimeout along with manually tracking the current time (using Date ) for your program step. For your case, try something like this:
function someAction(delta) {
This should be 140 beats per minute, using a higher resolution to avoid large delays. This is just a sample, but you will probably have to work more on it so that it can work optimally for your application.
source share