Pages: 1
  Print  
Author Topic: Mouse over event  (Read 1317 times)
Offline (Unknown gender) eppe
Posted on: August 26, 2013, 02:34:04 AM
Member
Joined: Aug 2013
Posts: 8

View Profile
Hi,

I would like to figure out the direction and speed of the mouse over an object.
I was planning to use some kind of mouse over event, but cannot find it, is it hidden somewhere?
Can someone think of another solution to do that?

Thank you!
Logged
Offline (Male) polygone
Reply #1 Posted on: August 26, 2013, 04:49:37 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
There is no event for that. You can just use teh step event:

if (place_meeting(mouse_x, mouse_y, id))
{
}
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #2 Posted on: August 26, 2013, 09:42:49 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
Each step, set a mouse_xprevious and mouse_yprevious. You can then get the direction using point_direction(mouse_xprevious, mouse_yprevious, mouse_x, mouse_y), and likewise, the speed using point_distance(mouse_xprevious, mouse_yprevious, mouse_x, mouse_y).

To also test if the mouse has passed through your object, use this:
Code: (EDL) [Select]
if (collision_line(mouse_xprevious, mouse_yprevious, mouse_x, mouse_y, obj_myobject, true, true)) {
  double dir, spd;
  dir = point_direction(mouse_xprevious, mouse_yprevious, mouse_x, mouse_y);
  spd = point_distance(mouse_xprevious, mouse_yprevious, mouse_x, mouse_y);
  // ...
}
mouse_xprevious = mouse_x;
mouse_yprevious = mouse_y;
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) Goombert
Reply #3 Posted on: August 26, 2013, 10:08:49 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
You guys, there is the mouse enter and mouse leave event.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #4 Posted on: August 27, 2013, 01:37:46 AM

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
You guys, there is the mouse enter and mouse leave event.
But I don't think that would help him as he wants it OVER the object.
Josh's code is how I have done something similar. Though I didn't use collision functions as I didn't need to know if I am over an object. I just had a drag variable which meant that I had dragged the object and if I released it while dragging then it would fly in the direction and speed of the mouse movement. Basically trowing balls with your mouse.
Logged
Offline (Unknown gender) eppe
Reply #5 Posted on: August 27, 2013, 03:30:56 AM
Member
Joined: Aug 2013
Posts: 8

View Profile
Thank you, it's very helpful.
I think I can do it like that.
Logged
Pages: 1
  Print