-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·52 lines (45 loc) · 995 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
// to enable debug, add an asterisk to the string in the next line
window.localStorage.debug = '';
const dSetup = debug('setup');
const dTick = debug('tick');
const dUpdate = debug('update');
const dDraw = debug('draw');
const dFps = debug('fps');
dSetup('starting');
let c = document.getElementById('c');
c.width = window.innerWidth;
c.height = window.innerHeight;
let ctx = c.getContext('2d');
let frameCount = 0;
let now = 0;
let then = 0;
let delta = 0;
const FRAME_TIME = 1000 / 60;
let audio = new AudioData();
const tick = () => {
dTick('new frame');
frameCount++;
now = performance.now();
dFps(1000 / (now - then));
delta = (now - then) / FRAME_TIME;
dUpdate('starting');
audio.update();
update();
dUpdate('ended');
dDraw('starting');
draw();
dDraw('ended');
then = now;
requestAnimationFrame(tick);
};
const W = c.width / 100;
const H = c.height / 100;
// globals
// globals
const update = () => {
};
const draw = () => {
};
dSetup('ended');
tick();