Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / mouse on image or object

Author
Message
Pauli
15
Years of Service
User Offline
Joined: 1st Jan 2009
Location:
Posted: 1st Jan 2009 13:50
Good morning.

How obtain condition (if), when is mouse on image (dbPasteImage or dbSprite) or on object ?
Or be enough condition (if), when be in rectangle (x,y,width,height).

Thank you.
Dark Inferno Studios
17
Years of Service
User Offline
Joined: 7th Nov 2006
Location: United Kingdom
Posted: 1st Jan 2009 14:40
Use dbMousePick(or whatever it is in DarkGDK, I'm using .NET, that's just a guess ) that will tell you the ID of the object under the mouse.

Hope this helps.

-Mike
Pauli
15
Years of Service
User Offline
Joined: 1st Jan 2009
Location:
Posted: 1st Jan 2009 14:50
to Dark Inferno Studios:
This(dbMousePick) function not exist.
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 1st Jan 2009 16:41 Edited at: 1st Jan 2009 16:42
To check if the mouse is over a sprite, you want to check if the mouse's position is greater than the sprite location and less than the sprite's location plus its size. So a function for that may look like this:



This code is untested but should so what you want. It can also be compressed a lot but I wanted to keep it clear.

As for checking if the mouse is in a rectangle, that method is very similar to the one above, except you have to provide the position and size:



Oh, and Dark Inferno Studios was talking about dbPickObject( ), however that's only used when picking objects in 3D and it looks like you want 2D.


Dark Inferno Studios
17
Years of Service
User Offline
Joined: 7th Nov 2006
Location: United Kingdom
Posted: 1st Jan 2009 16:49
AndrewT is correct, I was talking about dbPickObject().
I didn't notice you were doing 2D.

Sorry.

-Mike
Pauli
15
Years of Service
User Offline
Joined: 1st Jan 2009
Location:
Posted: 1st Jan 2009 17:03
to AndrewT:
Thank you.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 2nd Jan 2009 08:02
What if the sprite in question has been rotated?
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 2nd Jan 2009 16:50 Edited at: 2nd Jan 2009 16:59
Quote: "What if the sprite in question has been rotated?"


Assuming you don't want pixel-perfect collision, the only method I can think of is too:

-Divide the sprite into two triangles.
-Find the area of each triangle.
-Find out if the mouse is in either triangle by dividing it into three smaller triangles and comparing the sum of their areas with the area of the original triangles.
-If it is, then the mouse is over the rotates sprite.

However I'm probably overthinking this one by a mile, there's probably a much better solution.

EDIT:

Actually there is a much better solution, and that is to simply find out which side of each side of the rectangle the mouse is on. I'll try to come up with some code later.


Login to post a reply

Server time is: 2024-09-30 13:12:57
Your offset time is: 2024-09-30 13:12:57