summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-07-05 18:03:24 +1200
committerBen Bridle <ben@derelict.engineering>2025-07-05 18:03:34 +1200
commit39da0e91c2011966961071a1d3c138db32449dba (patch)
treebb4c9886f2564d5201ddb49f9fe4c8c5634f0d0b
parent8f54cac05765bb47488bec7242bb865a1dc1f7d4 (diff)
downloadbedrock-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.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/bedrock.js b/bedrock.js
index 7be6e4d..34ddc41 100644
--- a/bedrock.js
+++ b/bedrock.js
@@ -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);