Skip to content

Commit

Permalink
docs: Update Static Scene Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Sep 18, 2024
1 parent 6087c4f commit 98daa01
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion site/docs/02-fundamentals/04-scenes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ For more complex games, you might want more control over a scene in which
case you can extend [[Scene]]. This is useful for menus, custom loaders,
and levels.

### Adding a scene
### Adding a scene Dynamically

Use [[Engine.add]] to add a new scene to the game. Each scene has a `string` key you can assign. You can then use
[[Engine.goToScene]] to switch scenes which runs the scene lifecycle hooks.
Expand All @@ -82,6 +82,39 @@ game.add('mainmenu', new MainMenu());
game.goToScene('mainmenu');
```

## Static Scene Collection

You may also add scenes up front as part of your [[Engine]] construction. In the `scenes:` map you can specify a Scene constructor, a Scene instance, or a Scene Custom Configuration.

* Scene Constructors may extend `export class StartScreen extends ex.Scene`
* Scene Custom Configurations, like the one named `sceneWithCustomTransitionAndLoader:` can also take a scene constructor or an instances

One advantage of using Scene constructors is Excalibur will only construct your Scene when needed to present. This can save a lot of memory on the bigger games.

```typescript
const game = new Engine({
width: 800,
height: 600,
scenes: {
startScreen: StartScreen,
levelSelect: LevelSelect,
tutorial: Tutorial,
introLevel: new Level(Config.startingPuzzle),
endScreen: EndScreen,
sceneWithCustomTransitionAndLoader: {
scene: scene2,
loader: MyLoader,
transitions: {
out: new ex.FadeInOut({ duration: 500, direction: 'out' }),
in: new ex.CrossFade({ duration: 2500, direction: 'in', blockInput: true })
}
},
},
});
```



### Initialization

:::note
Expand Down

0 comments on commit 98daa01

Please sign in to comment.