Flick Gesture

Hey GMC! Making a mobile game. Need help with flick gestures. So I the flick gesture to be used to change menus in my game. Think snapchat and how you swipe left and right. So I have the code for movement and it seems to work nicely. I have one issue though.

So here's how I have it set up. There are 4 menu flick objects in my game, placed on the sides of each menu. There are three menus: The shop is on the left, with one menu flick object on the right side. The home menu is center, with 2 flick objects on both sides. Finally, the third menu for navigating inventory is on the right, with a flick object on the left side.

How I want it to work is if someone swipes their finger from the left side of the screen to the right while in the home screen, the screen will pan over to the shop menu (left of the home screen). Likewise swiping from the right side of the screen to the left while in the shop will return home etc.

Now, I have the movement working splendidly. My only issue is that I don't know how to tell the game which way the player is flicking. This results with the player being able to flick in either direction on the left side of the screen to go to the shop (you can put your finger on the left side of the home menu and then flick even more left and still go to the shop). I want it so that you can only swipe away from where you want to go to get there, if that makes sense. Thanks in advance :)
 
Last edited:
Hi Luke,

the best option to do this is to have a start position saved in a coordinate, and then a flick time, and an end position coordinate, you then use point direction to determine the direction swiped, the flick time will help to register the mouse as a flick rather than a long drag.

it should look something like this:

Code:
///create
v_xstart = 0;
v_ystart = 0;
v_isflick = 0;
v_flicktime = 0;
v_flicktimemax = .5;  //in seconds
Code:
///step
if device_mouse_check_button_pressed(0,mb_left)
{
   v_xstart = device_mouse_x(0);
   v_ystart = device_mouse_y(0);
   v_isflick = true;
   v_flicktime = 0;
}

if v_isflick == true
{
   v_flicktime += 1/room_speed;
   if v_flicktime > v_flicktimemax
   {
      v_isflick = false;
      exit;
   }
   if device_mouse_check_button_released(0,mb_left)
   {
      v_isflick = false;
      var dir = point_direction(v_xstart,v_ystart,device_mouse_x(0),device_mouse_y(0));
      dir = floor(dir/90);
      switch (dir)
      {
         case 0:
         {
            //right
            break;
         }
         case 1:
         {
            //up
            break;
         }
         case 2:
         {
            //left
            break;
         }
         case 3:
         {
            //down
            break;
         }
      }
   }
}
in each "case" you would count that as an input in one of 4 directions, if you need more than 4 directions, then the code can be changed, but this is as simple as i can think of it.

I hope this helps

Squareworx Studio

P.S. I wrote the code out of my head, there might be some syntax errors or whatnot, but it's the concept that counts.
 
Top