Mouse Swipe Controls

Hey, so I'm designing a mobile app, and since I can't test gestures on my pc, I want to code it to mouse controls. Got a single room with a view that covers a third of the room. Thus, the room is segmented into three parts. They are the home, shop and social pages. The home page is center, shop is left, and social is right.
(Think snapchat's different menu tabs, how you can swipe between them or Clash Royale's menu system and how you can swipe between it)

How should I go about this?
 
W

Wraithious

Guest
You could make some variables such as mouseswipex[0] mouseswipex[1] mouseswipey[0] mouseswipey[1] and then on mouse_pressed event set the mouseswipex[0] and mouseswipey[0] to the mouse x and y location, then on mouse release set the mouseswipex[1] and mouseswipex[1] to the mouse x and y locations and then you'll have the base to get any info off that like distance and direction, you could even have another variable be set to count steps for the length of time the mouse is pressed and get a mouse speed reading off that vs the distance swiped.

EDIT: I just messed around with this and here's an example code of how I did it, it will make an object move a certain distance, direction and speed for a certain amount of time based on how long you click and how far and in what direction you swipe:
create event:
Code:
for(i=0;i<10;i+=1;){mousesswipe[i]=0;}
step event:
Code:
//index 0 is start mouse x pos
//index 1 is end mouse x pos
//index 2 is start mouse y pos
//index 3 is end mouse y pos
//index 4 is distance of swipe
//index 5 is time of mouse swipe
//index 6 is swipe completed, or not swiped
//index 7 start timing swipe
//index 8 is start obj x pos
//index 9 is start obj y pos
if(mouse_check_button_pressed(mb_left))
{
for(i=0;i<9;i+=1;)//reset array
{
  mousesswipe[i]=0;
}
  mousesswipe[0]=mouse_x;
  mousesswipe[2]=mouse_y;
  mousesswipe[7]=1;
}

if(mouse_check_button_released(mb_left))
{
  mousesswipe[1]=mouse_x;
  mousesswipe[3]=mouse_y;
  mousesswipe[8]=x;
  mousesswipe[9]=y;
  mousesswipe[4]=point_distance(mousesswipe[0],mousesswipe[2],mousesswipe[1],mousesswipe[3]);
  if(mousesswipe[4]=0)//mouse was clicked and not swiped, reset array and set object to mouse position
  {
  x=mouse_x;
  y=mouse_y;
    for(i=0;i<9;i+=1;)
    {
      mousesswipe[i]=0;
    }
}
if(mousesswipe[4]>0)//mouse was swiped, continue
{
  direction=point_direction(mousesswipe[0],mousesswipe[2],mousesswipe[1],mousesswipe[3]);
  if direction>90 && direction<270 image_yscale=-1;
  if direction<=90 || direction>=270 image_yscale=1;
  image_angle=direction;
  speed=20-mousesswipe[5];
  if speed<1 speed=1;
  mousesswipe[6]=1;
}
}

if mousesswipe[7]=1 mousesswipe[5]+=1;
if(mousesswipe[6]=1)
{
  if(point_distance(mousesswipe[8],mousesswipe[9],x,y)>mousesswipe[4])
  {
    for(i=0;i<9;i+=1;)
    mousesswipe[i]=0;
  }
}
if(mousesswipe[4]=0)
{
  speed-=0.1;
  if speed<0 speed=0;
}
 
Last edited by a moderator:
K

KrashHash

Guest
When using touch controls one finger is the same as a left click and two fingers is the same as a right click to GM. The fingers location is the same as a mouse's location. Maybe code it so that while touching the screen that if the mouse_x moves a certain distance it will change screens, e.g.
Code:
//Create Event
mouse_x_start = 0;

//Step Event
if (mouse_check_button_pressed(mb_left)) mouse_x_start = mouse_x;
if (mouse_x < mouse_x_start-128)
{
      if (mouse_check_button(mb_left) room_xview[0] -= room_width/3;
}
Rough and probably the wrong way to do it but that's a pretty basic and you could go from there
 
Top