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 Questions

Author
Message
Varwulf
14
Years of Service
User Offline
Joined: 20th Feb 2010
Location: US of A
Posted: 20th Feb 2010 23:57
Hiya all,

I'm working on what would officially be my first game ever and am going to need a little bit of direction now and then. I have some C++ and VB knowledge, so I figured Dark GDK would be the best place to start. Anyway, that concludes my brief summary.

What I have is a menu screen so far with a background, various animated sprites on the screen, a version box, etc, but I also have several animated sprites functioning as buttons in a bmp format. There are three frames for the buttons, the first one being the normal display, the second being a "highlighted" version when the mouse is hovering over it, and the third being the "pushed in" version when it is clicked. What I need to know is what is the proper procedure for detecting a collision between the mouse and the button so I can get it to change from frame 1 to frame 2, and then back to frame 1 if the mouse moves off of it.

I am pretty sure I can figure out the clicking procedure, but the hovering procedure is what has be perplexed.

Otherwise, so far, everything is going well. Thanks for taking the time to read my issue.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 21st Feb 2010 00:46 Edited at: 21st Feb 2010 00:50
Consider the sprite to be a box. You need to figure out if the mouse cursor is inside the box, so you determine if the mouse's X coordinate is greater than the sprite's X coordinate, but also less than the sprite's X coordinate + the sprite's width. The same goes for the Y coordinates, but they deal with height.

(x, y) + width
.---------------.
| |
| |
| |
.---------------.
+ height



EDIT: Aww, the picture looked so much better in the forum message box...

Top left of sprite = (x, y)
Top to bottom = y + height
Left to right side = x + width

Success = Determination * Mood;
Varwulf
14
Years of Service
User Offline
Joined: 20th Feb 2010
Location: US of A
Posted: 21st Feb 2010 02:35
Thanks a bunch for the prompt response, I will give this a try and let you know how it turned out
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 24th Feb 2010 05:22
Another way you could try it is to have a sprite follow the mouse and then check to see if the sprite is colliding with the button with dbSpriteCollision().
haliop
User Banned
Posted: 24th Feb 2010 07:01
dbSpriteCollision will cause the CPU more work.

what i did is like this:
i'll explain in Images










enjoy.

Login to post a reply

Server time is: 2024-10-05 16:19:12
Your offset time is: 2024-10-05 16:19:12