blob: d1e089808dfeeace10d587e018a08bf9784cba31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import { Engine } from "../engine.js"
const fps = 60
/* cap the game's fps */
let msPrev = window.performance.now()
const msPerFrame = 1000 / fps
function tick() {
window.requestAnimationFrame(tick)
const msNow = window.performance.now()
const msPassed = msNow - msPrev
if (msPassed < msPerFrame) return
const excessTime = msPassed % msPerFrame
msPrev = msNow - excessTime
Engine.frame++
Engine.updateEngine()
}
export function startClock() {
tick()
}
|