Search code examples
javascripttouchtouch-eventpointer-events

Add touch events for mobile game


I am trying to create a game for crossing the road, I did for desktop version where I can move the player by using keys to cross the road, but now I want to do it for mobile version, any idea how to add keys to move the player on mobile devices. Thanks


Solution

  • Never developed a game - so i'm not sure if you are using jQuery too. If so there is a great plugin for handling mobile devices: https://jquerymobile.com/

    Instead of click you have events like 'touchstart' and 'touchend' and you can also directly combine them with click:

    on('click touchstart,function(){});
    

    Hope this helps!