coconut-platformer / game

2 stars 0 forks source link

Scenes #25

Open mrozbarry opened 5 years ago

mrozbarry commented 5 years ago

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:

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.