Double click help.

Started by Dualnames, Thu 05/07/2007 20:36:13

Previous topic - Next topic

Dualnames

Ok, well ever played CMI?
In some rooms you could double click at a door (the cursor changed shape over that hotpsot) and you entered the room instantly.
I tried to do something with timers but it can't work.
I don't have any troubles changing the cursor, so don't bother helping me with that. I just have  a problem with making a double click.
Feel free to make a code using Timer module.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ishmael

Basically, if clicked over eligable hotspot start counter, if another click on same hotspot (or within a certain radius of the first click's location) perform double click action; any other click or counter expires, cancel double-click.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Khris

Here's a tested and working example for the left mouse button:

Code: ags
#define DCDELAY 7

function left_click(bool single) {
  if (single) {
    // single-click code
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else {    
    // double-click code
    Display("Double-click detected!");
  }
}

int lastclick, mx, my;

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  if (lastclick>0 && lastclick<=DCDELAY) lastclick++;
  else if (lastclick>DCDELAY) {
    lastclick=0;
    left_click(true);
  }
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    if (lastclick && mouse.x==mx && mouse.y==my) {
      lastclick=0;
      left_click(false);  
    }
    else {
      lastclick=1;
      mx=mouse.x;
      my=mouse.y;
    }
  }
  else {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


The only downside: it takes DCDELAY frames before a single click is processed.

Dualnames

There is mone problem guys. I'm using CMI gui. So when I left click a counter starts and after some secs my GUI opens. :-*
I'll post the code so you can try in another way.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Kaspharm

That code works fine for me but how can I activate it in room script? - I am using LW BASS v.2.0 template - after double click on exit hotspot character has to change room - what i have to type in interact hotspot function? ;/

Khris

The easiest way is to use a custom cursor mode. I used Usermode1 and renamed it to "ChRoom".
Then I used this for the double click code:
Code: ags
  else {    
    // double-click code
    ProcessClick(mx, my, eModeChRoom);
  }


Now all you need to do is add an interaction for the new mode to the exit's hotspot, and put the .ChangeRoom() command inside.

Here's my working integration of the double-click code and the BASS click handler script: http://pastebin.com/G273xUgn

Kaspharm

Thank you kindly Khris - it works like a charm :)

SMF spam blocked by CleanTalk