How to close the game window

Archives Forums/MacOS X Discussion/How to close the game window

Ravl(Posted 2012) [#1]
Hello guys,

it is my first project on mac and the publisher (BFG) have this req:

Quitting: Game saves progress when exited through keyboard shortcuts (CMD + Q, CMD + Option + Esc)

and also when in window mode if the users presses the "x" button

I made a quick test and I observed that in window mode the app is not even closed when I press the window "X" button.

how should i handle all these?


Ravl(Posted 2012) [#2]
for CMD + Q, I made a simple check in my code, so that was easy. But still I have no idea how to make the app close when the user is pressing the X button.

Please help :)


d-bug(Posted 2012) [#3]
AppTerminate() is your friend.


GfK(Posted 2012) [#4]
What I'm doing (also for BFG) is capturing the AppTerminate() event and displaying an "are you sure?" dialog. Already have two games on BFG that use that method.

[edit] Your game looks great, by the way.

Last edited 2012


Ravl(Posted 2012) [#5]
@Gfk:
Thanks,

I just made a quick test and works fine. Also, how did you solve the COMMAND + TAB issue from full screen?

Thank you for the good words regarding my game :P I hope I will be able to release a Mac version, too and maybe an iPhone one.


GfK(Posted 2012) [#6]
I just made a quick test and works fine. Also, how did you solve the COMMAND + TAB issue from full screen?
I didn't. :/ Their specifications say that it's only necessary if the game engine supports it, which Blitzmax doesn't seem to. It does work fine in windowed mode though and that's the only thing they're strict on, really. So hopefully it'll go through OK.

There is an issue in Blitzmax under Mountain Lion that you might or might not be aware of: http://www.blitzbasic.com/Community/posts.php?topic=99166

I'm hoping my work-around (detailed in that thread) is acceptable.

Last edited 2012

Last edited 2012


Ravl(Posted 2012) [#7]
hmm. thanks. I did not encounter that issue from your link until now. Tested on several real machines and in my virtual machine..


DrDeath(Posted 2012) [#8]
Quitting: Game saves progress when exited through keyboard shortcuts (CMD + Q, CMD + Option + Esc)

I doubt that's even possible: cmd+opt+esc is supposed to kill every running application instantly.


GfK(Posted 2012) [#9]
I doubt that's even possible: cmd+opt+esc is supposed to kill every running application instantly.
It probably isn't possible, but your game should be saving progress at every appropriate point, so by the time the user pressed CMD+Opt+Esc, any required saving will already have been done anyway.


Ravl(Posted 2012) [#10]
well, my game saves progress every time you finish a scene. so for now I hope it's ok. I am waiting their QA feedback.


GfK(Posted 2012) [#11]
Same. Also save when the game options screen is exited, if the player has made any changes, or when the player switches between fullscreen/windowed. Data gets saved when it needs saving and you can do no more than that. I'm sure it'll be fine if you've covered all the bases.

I'm waiting on QA feedback too!


ima747(Posted 2012) [#12]
Just FYI to clarify for anyone interested. CMD + Option + Esc on OS X raises the force quit selector, which allows the user to force terminate an application. This is roughly equivalent to the task manager in windows which allows you to terminate running processes. And in the same way as on windows a) you can't interrupt it and b) you may not receive a terminate signal when it is sent. Technically on a mac you *might* get a terminate signal prior to the app being force closed (I believe the OS sends a polite kill then waits a couple seconds before sending a hard kill) but I'm pretty sure BMax doesn't trap that signal so you won't see it.

No idea why a publisher would mention note of CMD + Option + Esc since it's purpose is to circumvent the normal task ending procedure (since it should only be used when a task is already exhibiting failure, like running wild or failing to terminate by normal means).

BMax *should* direct all "normal" terminate requests through AppTerminate(). Including but not limited to application menu quit (including keyboard shortcut, note that keyboard shortcuts only work when you're not trapping key input as you will be doing most of the time in BMax), closing the game window in non MaxGUI apps (this is not strictly an application terminate, but UI guidelines dictate that for single window apps like Games tend to be that the app should terminate at that time since there is nothing left for the user to do.), or selecting quit from the app's dock icon (right click, control click or just long click the icon to get the popup menu). All that should get funneled through AppTerminate, and as such if you implement a polite close, including confirmation dialog excepting in the case of games/apps too small in scope to warrant it, such as Reminder or Notes where date is auto saved and resuming takes no time, then you should be UI best practices compliant to a level acceptable by most users/publishers.

Optionally detecting when the app is switched to background and going into windowed mode from full screen (and preferably returning to full screen mode when the app gains focus again) is a standard a lot of games employ but is not strictly required. If you plan to distribute on the app store and you have a windowed and full screen mode, you are required to let users switch between them with CMD + Return. This can be tricky in BMax. the simple solution for the app store is just stick to one or the other depending on what's most appropriate for the game and then you don't have to implement the switch... not best for users but it is allowed and a helluva lot easier :0)

Last edited 2012


Captain Wicker (crazy hillbilly)(Posted 2012) [#13]
While Not AppTerminate()

Wend