Step 6 - Refactor to a Scene
Up to this point we've been using the default scene, which is great for small prototypes. However we want to keep main.ts clean so we'll move our game composition and initialization logic into a ex.Scene.
Create a new file called level.ts, we can put our initialization logic in onInitialize this will be called once before the scene is shown for the first time. If you need to have logic run when the scene is shown every time look at onActivate and onDeactivate.
It is often useful to stash common logic for your game in a scene, for example restarting, game over, saving state, etc.
typescript
typescript
Now in our main.ts we register the scene and go to the named scene after we start
typescript
typescript