Workaround: Pause menus with MMF2's built in pause function (help me improve this?)
I've discovered a nice little method to put a pause menu into your game without using the Q&A object or manually pausing every object, it could do with some work though... Essentially I use MMF's built in pause feature but I cheat a little, here's what I have so far...
(Note that here I have done this first move in two separate events, if you make the menu visible and pause the application in the same event it will pause the application first as the pause action takes priority.)
Mouse clicks on pause button + [pause menu object(s)] is invisible:
- Make [pause menu object(s)] visible
Pause object(s) is visible + Only one action when event loops:
- Pause the application and resume when any key is pressed (On iOS, this resumes when you tap anywhere on screen)
[pause menu object(s)] is visible + Mouse pointer is over [menu item]:
- [Execute the chosen menu item's function]
- Make pause menu object invisible
See, on iOS, MMF reads the mouse pointer position as the last touch, imagine an invisible mouse pointer which follows your finger then stays where you left it when you aren't touching the screen. What happens is that when the app is resumed, the last touch will be where you tapped to resume the game, so you can detect a tap on a pause menu item by looking at the mouse pointer position when resuming the app. Note that I use the visibility of the menu objects to check for resume as it won't check the mouse position on the 'end of pause' event for some reason. For more control, you could use an internal flag.
The only problem I'm having is how to react when the user taps somewhere where there isn't a menu item - it will resume no matter where they tap and we get away with this by just detecting where that tap WAS when the game resumes.
There are two options... Method A is to remove the menu from the screen when you tap anywhere other than the menu items, meaning if you tap anywhere on screen where there isn't a menu item, it will resume the game.
Method B (AFTER the existing events):
[pause menu object(s)] is visible:
- Pause the application and resume when any key is pressed
This one pauses the game again if the tap wasn't on a menu item. This is the more professional method but frustratingly it's not quite right because the game will resume for a split second and then pause again, giving you a split second of audio and sometimes some game movement.
So it seems it's best to have something which says "PAUSED. Touch the screen to continue." With the quit buttons etc. underneath, but it'd be nice if I or somebody could find a way to prevent the split second of resumed gameplay when using method B. Any ideas?
Note: You'll find this usually works on the device but not on the Windows runtime