This is a sort of 'internal' or minor state within a major state?
You could use a flag or enum to keep track of current minor state and perform certain functions based on that enum/bool. e.g. if the enum states that map is loading, don't perform updates on gameplay.
Hey, Hapax. From what I understood, this might be an internal or a small state. All it does is show a "Loading map. Please wait..." screen for as long the map is being loaded, as stated before a few times. If you looked at my github you would of have seen the state machine working flawlessly (as stated before as well), so opting for enums or whatever else is not what I'm struggling with.
There are many different approaches for something like that. IMO you shouldn't even have to load your stuff asynchronously, unless it really takes a while and is hidden behind something else, like gameplay. If you've got a loading screen, just do it in your main thread.
One approach I'd try, is to keep other states clean of your loading mechanic:
- States queue their preloaded resources in their init() or enter() function, which is called once the state activates.
- Once that call is done, you could check how many resources there are to load, if it's above some threshold, a loading state is automatically pushed/entered, which will render the loading screen and load assets.
- The loading state is left once all resources have been loaded/processed, returning control to the "new" state entered before.
As for transitions and such, this really depends on what kind of transitions you want (like fading to/from black or alpha blending).
Hi, Mario. About asynchronous calls, I believe this is not "optional" but a must have. You should never have your game window frozen, not even for a few half seconds, but that just my opinion. However, in this case, the map loading does take a while (13 seconds in debugging and ~700 milliseconds on release) and is hidden behind the PlayingState, if that's what you meant.
The states themselves does load or do whatever else on their "init/enter" functions, but that applies only for the LoadingState (which is not the same as map loading) and it does work as expected (asynchronously with a progress bar). Having fade effects right now would just be a "plus". I'm making it very simple and focusing on only showing that "Loading...." string on screen.
I believe none of you got me right so I'll just try to explain clearer and again:
I'm stuck on the part that I will have to display the map loading screen (lets call it TransitionState) when the map loads, either from map.load() (forced) or from the map.update() function (dynamic), when the player enters in a teleport, for example. Like I said before, the only way I could come up with is to use the observer pattern. Map would be a LoadingNotifier and the PlayingState a LoadingListener. Is that right or are there any easier/other ways people usually do that? Hope its clearer now.
Thanks for all the input, all of you.