0

I made a javascript game and I was wondering how can I adapt it so I can play this game on mobile too.

All I want is to replace arrow keys events with mobile swipes;

My moving function looks like this:

    switch (e.keyCode) {

            case 37:
                    //do this
            case 38:
                    //do this
            case 39:
                    //do this
            case 40:
                    //do this
        }

How can I add another switch case for swipe down (from a mobile device) is it hard to do?

PS preferably without jQuery

1 Answers1

0

You can try to achieve this by addEventListener('touchstart',handleTouchStart) and addEventListener('touchmove',handleTouchMove) and write the handleTouchStart & handleTouch functions and compare the touch position to the previous position each time to get the direction.

Or just use hammerjs library => https://hammerjs.github.io/

Dor Ben Itzhak
  • 285
  • 2
  • 5