We should be able to support scenes. Examples of scenes would be:
Title scene. Show logo, and prompt player to press a key to begin.
Game scene. We basically have this one already
Game over scene. When you die, what do we show?
We should also have some way to transition scenes.
I think we would want a SceneManager class that would allow us to "stack" scenes. Our initial scene would be the title, and hitting a button would stack the game scene on top. When the player is done playing, the game scene is popped off, and we end up back at the title scene.
The api could probably look like:
const sceneManager = new SceneManager(new TitleScene());
sceneManager.push(new GameScene());
sceneManager.pop();
sceneManager.render();
A scene probably has an api like this:
class BaseScene {
onPush() {} // What to do when this scene gets pushed on the stack
onPop() {} // What to do when this scene gets popped from the stack
render(prevScene) {} // What to do on render.
}
Of course different scenes may have their own custom functions,
One thing that could be interesting is making Scene#render be part of a pipeline. For instance, there may be cases when we want to render a scene over-top of another, we could call prevScene.render() inside the current scene render and create an overlay. Maybe for the game over scene, we would want to show some information on top of the world.
We should be able to support scenes. Examples of scenes would be:
We should also have some way to transition scenes.
I think we would want a
SceneManager
class that would allow us to "stack" scenes. Our initial scene would be the title, and hitting a button would stack the game scene on top. When the player is done playing, the game scene is popped off, and we end up back at the title scene.The api could probably look like:
A scene probably has an api like this:
Of course different scenes may have their own custom functions,
One thing that could be interesting is making
Scene#render
be part of a pipeline. For instance, there may be cases when we want to render a scene over-top of another, we could callprevScene.render()
inside the current scene render and create an overlay. Maybe for the game over scene, we would want to show some information on top of the world.