Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Buttons and boxes...

This topic is 6060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody... What is the best way to implement buttons and boxes in a game. Just reading the mouse coordinates is a bit stupid, because there will be screens without a button on that spot. Isn''t there a function registering thingie, just like with Borland C++ builder whereby you just simply let a button be attached to a funtion. That reduces the lines of code, the number of bugs, and it wouldn''t surprice me that it would be faster too, because you don''t have to check for mouseinput every time. I need this info to build a GUI, but I don''t want to use the standard windows-windows. Just my own thing. It would be nice if someone could help me...

Share this post

Link to post
Share on other sites
Why not only check the co-ordinates on screen when you know the screen with the button will be up?

Begin Game Loop

if(ViewType == ScreenWithButton)
Call FunctionCheckForThatButton

End Game Loop

Ballistic Programs

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Why not have a linked list of buttons that are on screen, then simply traverse this list of buttons and check coordinates within, and if the mouse is pressed over it.. have pointers to functions within the linked list that are set to the proper functions you wish to be called when events happen. You can either have Button Down/Up or just button clicked.. or both, or neither, etc, etc. You can even have generic functions for button down/up that automagically draw the buttons depressed when mouse down + mouse over. It''s really pretty simple actually.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!