YoYo Games Wiki

Double click

From YoYoGames Wiki

(Redirected from Double Clicks)

General idea

Sometimes it is necessary to determine double click on an object from single clicks. Double click differs from a serie of two single clicks in two aspects:

  • mouse is not moved between clicks,
  • time interval between clicks is not too long.

The next code shows the general solution for this problem.

Put following code fragment into Create event and into alarm0 event:

 click=0;

Put following code fragment into mouse click event:

 // first test if already clicked
 if(click>0){
   // next test if mouse is still
   if(point_distance(click_x,click_y,mouse_x,mouse_y)<4){
     /* put reaction on double clicks here */
     click=0;
     exit;
   }
 }
 // just single click
 click = 1;
 click_x = mouse_x;
 click_y = mouse_y;
 alarm[0] = 15; // half a second if room_speed is 30

More customization

This code can be easily change so it will handle triple or more complex clicks. Also, the default interval can be changed into something more appropriate to your need, i.e. it can depend on the room_speed variable.