Skip to content

Commit 2ed0030

Browse files
author
Lionel Laské
committed
Add touch events handling for canvas
1 parent c277fe7 commit 2ed0030

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

activities/Stickman.activity/js/activity.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,22 @@ define([
635635
canvas.addEventListener('mousedown', handleMouseDown);
636636
canvas.addEventListener('mousemove', handleMouseMove);
637637
canvas.addEventListener('mouseup', handleMouseUp);
638+
canvas.addEventListener('touchstart', function(e) {
639+
e.preventDefault();
640+
if (e.touches.length > 0) {
641+
handleMouseDown(e.touches[0]);
642+
}
643+
}, { passive: false });
644+
canvas.addEventListener('touchmove', function(e) {
645+
e.preventDefault();
646+
if (e.touches.length > 0) {
647+
handleMouseMove(e.touches[0]);
648+
}
649+
}, { passive: false });
650+
canvas.addEventListener('touchend', function(e) {
651+
e.preventDefault();
652+
handleMouseUp(e);
653+
}, { passive: false });
638654

639655
// Control buttons
640656
document.getElementById('add-button').addEventListener('click', addFrame);

0 commit comments

Comments
 (0)