-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.js
45 lines (37 loc) · 1.18 KB
/
Main.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
// Canvas & context
let canvas = document.getElementById("canvas");
const gl = canvas.getContext('webgl2', { premultipliedAlpha: false });
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let layer;
function start() {
layer = new MainLayer();
loadPreset(0);
loop();
}
function loop(){
layer.update();
layer.draw();
requestAnimationFrame(() => loop());
}
const ongoingTouches = [];
window.addEventListener("pointerdown", handleStart, false);
window.addEventListener("pointermove", handleMove, false);
window.addEventListener("pointerup", handleEnd, false);
window.addEventListener("pointercancel", handleEnd, false);
function handleStart(event) {
ongoingTouches.push(event);
layer.handleTouch(ongoingTouches);
}
function handleMove(event) {
let movingPointers = ongoingTouches.findIndex((tch) => tch.pointerId == event.pointerId);
if (movingPointers >= 0) {
ongoingTouches.splice(movingPointers, 1, event);
layer.handleTouch(ongoingTouches);
}
}
function handleEnd(event) {
let touchIndex = ongoingTouches.findIndex((tch) => tch.pointerId == event.pointerId)
ongoingTouches.splice(touchIndex, 1);
}
start();