Switching Scenes
Once your game reaches a certain size, you will want to start switching between scenes. That might be switching from a intro or menu to the game or from one level to another.
The most important function to know here is WL.scene.load(),
which will replace the current scene with a .bin
filename or URL you pass it for loading.
This could be an example of a component that switches to another scene after a certain amount of time:
Preloading Scenes
While the scene will keep running while the next is loading, it will still cause a delay between when the load was initiated and the next scene appearing for the user.
To minimize this scene, you can put the following HTML tags into the <head>
or your
index.html
:
Caveats
Loading a scene will currently not clear event listeners you might have registered to DOM elements. You are responsible for removing event listeners when the next scene loaded to avoid unexpected behaviour:
|
|