Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Control the direction of a game object on a mobile device

  1. Jul 31, 2015 #1
    This is more of a user experience question. I'm starting to remake a game (see http://playclassicsnake.com/play [Broken]) that works on mobile just as well as desktop. On desktop, one controls the snake (the lime green links) with the arrow keys, but I need a different way to do it on mobile. I tried using an API (http://hammerjs.github.io/) to detect finger swipes, but the problem I was encountering is that the phones interpret up and down swipes as wanting to scroll up and down on the page. I need some other way. Any ideas?

    Game logic https://github.com/jamkin/Snake/blob/master/SnakeGame/Scripts/game.js [Broken].
    Last edited by a moderator: May 7, 2017
  2. jcsd
  3. Jul 31, 2015 #2


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    Instead of using a swipe, couldn't you just detect a touch and go in that direction?
  4. Jul 31, 2015 #3
    The directions it moves are straight up, straight down, straight left, straight right. So if I have touch control the direction, do I put some icon like


    on the board and the user has to tap on the arrows of the icon???

    Another option I thought of is having tap move the snake's current direction by 90 degrees to the right. For example, if the snake is moving to the left and the user wants to move down, they have to tap 3x very quickly.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook