[SOLVED] when does mouse click take effect?

Started by johanvepa, Sun 03/01/2016 16:10:34

Previous topic - Next topic

johanvepa

Will the event function on_mouse_click register the mouse click as soon as mouse button is pressed or only when it is pressed and released? Will on_mouse_click be called if I press and hold the mouse button?

Crimson Wizard

#1
Contrary to how it usually works in various systems, in AGS on_mouse_click is called whenever mouse button was pressed down.

If you want finer control over mouse buttons, use Mouse.IsButtonDown in repeatedly_execute (or repeatedly_execute_always).

Example:
Code: ags

bool mouse_was_down;
function repeatedly_execute() 
{
  if (Mouse.IsButtonDown(eMouseLeft))
  {
    if (mouse_was_down)
    {
      // mouse button is still held down
    }
    else
    {
      // mouse button was just pressed down
      mouse_was_down = true;
    }
  }
  else
  {
    if (mouse_was_down)
    {
      // mouse button was finally released
      mouse_was_down = false;
    }
    else
    {
      // mouse button is still released
    }
  }
}

johanvepa

#2
Would it be correct to say that on_mouse_click is called the instant I release the click?
And that it is not called yet as long as I hold the button down?

Crimson Wizard

Quote from: Nanuaraq on Sun 03/01/2016 20:02:07
Would it be correct to say that on_mouse_click is called the instant I
Code: ags
release
the click?

No, as I said in my previous post, it is called the moment when you press button down.

johanvepa

I read what you said, only I misunderstood the context. But I think I get it now. And thank you very much. In combination with mouse.IsButtonDown, this makes for some nice interactions. Thank you.

Monsieur OUXX

you can use this module to have more control of different ypes of clicks on different types of objects (controls, guis, etc.) http://www.adventuregamestudio.co.uk/forums/index.php?topic=49989.0
It's bascially a fancy version of Crimson wizard's code snippet.
 

Crimson Wizard

Quote from: Monsieur OUXX on Mon 04/01/2016 12:15:08
you can use this module to have more control of different ypes of clicks on different types of objects (controls, guis, etc.) http://www.adventuregamestudio.co.uk/forums/index.php?topic=49989.0
This is interesting, I was once designing a module of common idea.

SMF spam blocked by CleanTalk