-
-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Break out overlays docs (#2384)
The docs for overlays were a bit hard to find so I broke them out to its own section. They could need some some updating too with more examples and instructions.
- Loading branch information
Showing
3 changed files
with
48 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Overlays | ||
|
||
Since a Flame game can be wrapped in a widget, it is quite easy to use it alongside other Flutter | ||
widgets in your tree. However, if you want to easily show widgets on top of your Flame game, like | ||
messages, menu screens or something of that nature, you can use the Widgets Overlay API to make | ||
things even easier. | ||
|
||
`Game.overlays` enables any Flutter widget to be shown on top of a game instance. This makes it very | ||
easy to create things like a pause menu or an inventory screen for example. | ||
|
||
The feature can be used via the `game.overlays.add` and `game.overlays.remove` methods that mark an | ||
overlay to be shown or hidden, respectively, via a `String` argument that identifies the overlay. | ||
After that, you can map each overlay to their corresponding Widget in your `GameWidget` declaration | ||
by providing an `overlayBuilderMap`. | ||
|
||
```dart | ||
// Inside your game: | ||
final pauseOverlayIdentifier = 'PauseMenu'; | ||
// Marks 'PauseMenu' to be rendered. | ||
overlays.add(pauseOverlayIdentifier); | ||
// Marks 'PauseMenu' to not be rendered. | ||
overlays.remove(pauseOverlayIdentifier); | ||
``` | ||
|
||
```dart | ||
// On the widget declaration | ||
final game = MyGame(); | ||
Widget build(BuildContext context) { | ||
return GameWidget( | ||
game: game, | ||
overlayBuilderMap: { | ||
'PauseMenu': (BuildContext context, MyGame game) { | ||
return Text('A pause menu'); | ||
}, | ||
}, | ||
); | ||
} | ||
``` | ||
|
||
The order of rendering for an overlay is determined by the order of the keys in the | ||
`overlayBuilderMap`. | ||
|
||
An example of this feature can be found | ||
[here](https://github.com/flame-engine/flame/blob/main/examples/lib/stories/system/overlays_example.dart). |