Skip to main content
GameDev.net gamedev.net
🔒 Locked

Game buttons....

Started by hammerstein_02 Jul 21, 2002 at 8:00 AM 3 replies 250+ views
Original Post
hammerstein_02
hammerstein_02
I am writing a small set of card games and I want to put buttons on the screen. So far my idea is this, create a class, cObject and create a linked list of cObjects, when I click or move the mouse scroll through the list and decide if the mouse is within a button zone.. if it is generate the relevant event, if not move to the next object. I plan on figuring out function pointers and sending my buttons the relevant function as I create them. Am I even heading in the right direction? Should I continue trying to do this or is there a better way? =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=
BitBlt
BitBlt
That seems like a workable solution. Just be sure to keep the most used buttons at the top of the list, that way they will be checked first, since chances of them being the once "hit" is greater than a less used button. Also don''t check every time you move the mouse, just every time you click.



Friends don''t let friends use dial-up.
hammerstein_02
hammerstein_02
I want to detect mouse overs as well, so I would have to check the buttons everytime the mouse moves, is there an efficient way of doing this?
NightWraith
NightWraith
It depends on the layout of your buttons...

If they''re going to be layed out in a row, at regular intervals, your laughing.. Simply put them in an array/List and do a simple bit of maths to determine the location.

If you''re going to scatter them over the screen, then a List is a reasonable solution... A hash table would be faster.

What i''ve found in my game is that my buttons tend to be in groups, so what I did was to put them on a "Frame" each "Frame" has a list of the buttons that are on it. Then I test first against the Frames and then against the matching ones buttons. The resulting search is faster than a straight liniar search.

NightWraith
NightWraith
nonnus29
nonnus29
I''ve been playing with this recently too. What I did was every time I loop through the code and update my game and draw the next frame I pass the current mouse coordinates to all the objects currently visible (buttons, NPCS, whatever) and they determine if the mouse is over themselves and since they draw themselves they draw themselves in the mouse over state. I will never have more than ten objects active this way so it works pretty good. The next thing I''m going to do is implement a frame system like NightWraith mentioned.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.