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 / My Quit button isn't working

Author
Message
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 5th Jun 2009 09:38
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:


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:


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?
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 5th Jun 2009 18:58



Your signature has been erased by a mod
Flatbattery
15
Years of Service
User Offline
Joined: 2nd May 2009
Location: Brum, UK
Posted: 5th Jun 2009 20:46
Unless you specify otherwise the Escape key will always exit your program anyway. It's default to GDK

How are you using your "exit" variable to exit your program?
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 6th Jun 2009 20:33
Ack, I figured it out. My own fault.

I forgot that the "main" section for a Dark GDK program is actually a loop. It makes perfect sense, of course, it wouldn't work otherwise. Even so, I couldn't figure out why when I left my menu screen it would isntantly reload again. That's because even when I left the menu loop, I didn't provide any means to exit the GDK main loop, and it just looped again and brought up the menu screen again.

I fixed it. Now the exit state of the game is controlled by a gamestate variable, and I can pass it to functions by reference so they can quit the game if they want to.

Login to post a reply

Server time is: 2024-11-25 10:44:44
Your offset time is: 2024-11-25 10:44:44