I'm making a simple 2d menu, like you might see when you start up a game. Mostly it's for practice. I got it to load up images for all the options, and for them to highlight when you position the cursor over them.
I figured the "Quit" button would be the quickest and easiest to code, just so I would know how to properly get the buttons working properly.
But for some reason, when I click the Quit button it just flashes white for a second, then the menu pops back up again. When I press Escape to quit it functions perfectly.
Here are the code snippets:
if ( dbEscapeKey() )
{
exit = true;
}
This part works - If I press the Escape key, it leaves my "menu" function, releases my menu images from memory, returns to the main function, and terminates the program. exit is simply a bool letting it know to leave the menu function or not.
but for some reason this doesn't work:
if (
(dbMouseX()>MenuPosX) &&
(dbMouseX()<MenuPosX+360) &&
(dbMouseY()>MenuPosY+165) &&
(dbMouseY()<MenuPosY+215)) &&
(dbMouseClick()==1)
)
{
exit = true;
}
The "MenuPos" stuff is just what I'm using to position the buttons on my menu (I can change all the buttons just by changing the MenuPos values at the beginning of the function). It designates a rectangular grid, wherein lies my button. This grid works fine for my "mouseover" function, making the Quit button highlight when I mouse over it.
And it also recognizes when I click inside it - or else I wouldn't even get the white screen for a second before my menu reloads itself.
But why is the Escape key working to exit the function, but the Quit button isn't?
I realize there might be an easier way to designate a button than giving the 4 coordinates, and I am interested in learning that. Even without that, though, this
should work, as far as I can tell. Am I missing something?