Unload a lower scene. Only use this if the lower scene requested to be unloaded, or if you're certain that you want to reload the lower completely. Otherwise, this can easily lose state or break functions.
Get the current scene, or a specific index.
Uses Array.at under the hood, so -1 is the
top scene, -2 is the lower scene, etc.
During instantiation, the stack is not shifted relative to during event/lifecycle functions. The only difference is that during load, scene.get(-1) of course returns no value.
Make a scene into an instance and dispatch load into it.
Pop the current scene off the stack, calling quit on it and
dropping the instance reference.
If the lower scene had called pushScene with the second arg (unload)
set to true, it will be re-loaded. Otherwise it will continue where it
left off. Either way its load fill fire.
To clear the stack, just run:
while (like.popScene());
Push a scene to the scene stack and run it.
A function that creates and returns a scene instance, which is just event handlers.
If a scene calls scenes.push(nextScene, true), it will be unloaded
and re-constructed upon the upper scene calling scenes.pop().
Good for resource-intensive
scenes or ones that rely heavily on their lifecycle. If you do want
the lower scene to know what happened in the upper while unloaded, (i.e. overworld
updating with a battle), consider using scene composition instead, or
using localStorage to track persistent game state.
If a scene calls scenes.push(nextScene, false), it will stay loaded:
this means when we pop the upper, it will simply continue running, though
load will be called. Assets will of course stay loaded in during that time.
Further, with unload disabled the upper scene now has the ability to reference
the instance that called scene.push and call down to it in a generic way
via scene.get(-2)
See Scene for more detail -- while stacking is good for certain things, you're likely looking for Scene Composition.
Set the current scene at the top of the scene stack. If the stack is empty, push it onto the stack.
The new scene is instantiated after the old one is quit and removed from the stack.
Set cannot clear the current scene; for that use pop.
is a Scene (factory pattern).
Optionalinstance: SceneInstanceis an optional preloaded instance.
Scenemanager is the entry point for the LÏKE scene system. Without it, there are no scene functions; it's entirely modular.
Usage:
For arbitrary scene management (non stack based), just use SceneManager.set which switches out the stack top.
For stack-based, use SceneManager.push and SceneManager.pop. Note that for stack-based games, it is wise to put the first initialization in as a callback-based system rather than going straight to scene. This allows for easy resets / game overs.
Note that the SceneManager sets like.handleEvent. To get rid of scene functionality entirely, simply set it back to default.
Otherwise, the
SceneManagerstays allocated even if the scene stack was cleared.