Archived

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

Frankie68

Buttons and boxes...

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?
ie

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.

Billy

Share this post


Link to post
Share on other sites