diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-07-05 18:03:24 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-07-05 18:03:34 +1200 |
commit | 39da0e91c2011966961071a1d3c138db32449dba (patch) | |
tree | bb4c9886f2564d5201ddb49f9fe4c8c5634f0d0b | |
parent | 8f54cac05765bb47488bec7242bb865a1dc1f7d4 (diff) | |
download | bedrock-js-39da0e91c2011966961071a1d3c138db32449dba.zip |
Support touchscreen devices
Click events on touchscreen devices are handled by the touchstart and
touchend events. These events will now enable and disable the pointer
device, move the pointer position, and press and release the primary
pointer button.
-rw-r--r-- | bedrock.js | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -517,6 +517,17 @@ function EmulatorElement(options) { } } + emulator.touchStart = function(e) { + if (e.changedTouches.length) { + emulator.mouseMove(e.changedTouches[0]); } + br.dev.input.applyActive(true); + br.dev.input.applyButtons(0x01); + } + emulator.touchEnd = function(e) { + br.dev.input.applyActive(false); + br.dev.input.applyButtons(0x00); + } + fullscreenButton.addEventListener('click', emulator.toggleFullscreen); stateButton.addEventListener('click', emulator.toggleStatePanel); runButton.addEventListener('click', emulator.runProgram); @@ -528,6 +539,9 @@ function EmulatorElement(options) { canvas.addEventListener('pointermove', emulator.mouseMove); canvas.addEventListener('mousedown', emulator.mouseDown); canvas.addEventListener('mouseup', emulator.mouseUp); + canvas.addEventListener('touchstart', emulator.touchStart); + canvas.addEventListener('touchend', emulator.touchEnd); + canvas.addEventListener('touchcancel', emulator.touchEnd); canvas.addEventListener('mouseenter', emulator.mouseEnter); canvas.addEventListener('mouseleave', emulator.mouseExit); canvas.addEventListener('wheel', emulator.mouseScroll); |