precision-game/js/tick.mjs
trans_soup af3ec008c9 pass deltatime in seconds during ticks.
previously it was passed in milliseconds.
2023-10-25 20:08:29 +02:00

15 lines
306 B
JavaScript

const tickers = [];
export function register_tick (callback) {
tickers.push(callback);
}
let last_tick = new Date().getTime();
export function tick () {
const deltatime = new Date().getTime() - last_tick;
last_tick += deltatime;
for (const callback of tickers) {
callback(deltatime / 1000);
}
}