During early development of my game I did not really regard how the game will be paused in case the player gets interrupted. I figured it shouldn't be anything too difficult so I left it as something I would look into once I got the core of the game finished.
I'm here now and trying to figure out a way to pause my game is very difficult, from my point of view anyway.
As of now I followed a few tutorials to get to where I am today, mainly tutorials from ASGamer. The preloader and menu screens tutorial that can be found at that site is what I used and so far I've had a few problems which I will ask later.
Anyway I find it difficult to wrap my head around how I would be able to pause or suspend game play when the user presses a designated key. I guess I should explain how my game functions.
I have 3 frames in my main timeline.
First frame is for the preloader, simple.
Second frame is where the game is. It has my asset holder and all my scripts run when on that frame.
Third frame is stop(); action.
Once the preloader finishes my the "Menu Screens" starts, this is the tutorial I followed. It loads and unloads movieclips with UnLoad() and Load().
I use Load() to load the main menu which happens at the beginning, then use UnLoad() to unload the current menu then load the next designated menu, for example Main Menu -> the Game I use Unload(new GameMenu(stage));
The stage is constantly passed back and forth with these menus so it gets confusing sometimes.
In the GameMenu is where I run the game from, I made a class GamePlay that extends MovieClip. From there it spawns the players and enemies and plays as a normal game, this is where my problem begins.
First I tried to create a key handler to get key presses from the user. At one point it worked the key presses were registering but after I made some changes to other scripts the key presses were not recognized any more. So I moved the key presses to my Main.as which is the main script that my fla uses. The keyboard events work fine, but now actually stopping the game...how do I even begin? I would have to stop all movieclips and eventlisteners until the user presses the designated pause button again, how would I accomplish this?
I read somewhere that using state machines is the best bet for having a pause in any game, but I'm not sure how to do this but I'm sure there are tutorials and blogs I can read to make a state machine, but if I did add one or make one would I have to redo all my code to accommodate state machines?
ENTER_FRAME
event. So when the game needs to be paused, the listener is removed. – user1385191