Skip to content

Commit

Permalink
feat: add touch event handling to compositor example
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Aug 13, 2020
1 parent 1cb3e51 commit bcf424b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/examples/compositing/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ async function init(): Promise<null> {

animate();

const zoomFactor = 2.5;

window.addEventListener("resize", () => {
layerRenderer.context.canvasFramebuffer.resize();
});
canvas.addEventListener("mousedown", (mouseEvent: MouseEvent) => {
if (mouseEvent.button === 0) {
layerRenderer.zoomScale = 4.0;
layerRenderer.zoomScale = zoomFactor;
}
});
canvas.addEventListener("mouseup", (mouseEvent: MouseEvent) => {
Expand All @@ -70,6 +72,18 @@ async function init(): Promise<null> {
// console.log(layerRenderer.panPosition);
}
});
canvas.addEventListener("touchstart", () => {
layerRenderer.zoomScale = zoomFactor;
});
canvas.addEventListener("touchend", () => {
layerRenderer.zoomScale = 1.0;
});
canvas.addEventListener("touchmove", (touchEvent: TouchEvent) => {
layerRenderer.panPosition = new Vector2(
canvas.width * 0.5 - touchEvent.touches[0].clientX,
canvas.height * 0.5 - touchEvent.touches[0].clientX,
);
});

return null;
}
Expand Down

0 comments on commit bcf424b

Please sign in to comment.