-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 791 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
import Floater from './floater.js'
import Background from './background.js'
const DEBUG = true
function debug(s) {
if (DEBUG) console.log(s)
}
window.addEventListener('DOMContentLoaded', () => {
const canvas = document.getElementById('canvas')
const ctx = canvas.getContext('2d');
const floater = new Floater();
const background = new Background();
function tick(){
background.draw(canvas, ctx)
floater.draw(canvas, ctx)
}
let lastTick
setInterval(() => {
if (lastTick) {
debug('canceling last tick')
window.cancelAnimationFrame(lastTick)
}
lastTick = window.requestAnimationFrame(() => {
tick()
lastTick = undefined
})
}, 17) // 16,666 for 60fps
})