From 284e993ab1011132cdd226df55c5ba8e6f792dc7 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Wed, 20 Jan 2021 17:01:50 +0100 Subject: [PATCH 1/2] Added a required to GameWidget and updated the docs --- CHANGELOG.md | 2 ++ doc/game.md | 5 ++++- lib/src/game/game_widget.dart | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f16ea35ff3a..42ab3a8fd98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ - Adding standard for `SpriteComponent` and `SpriteAnimationComponent` constructors - Move files to comply with the dart package layout convention - Fix gesture detection bug of children of `PositionComponent` + - The `game` argument on `GameWidget` is now required + - Added a note to the `GameWidget` docs mentioning to not instantiate inside a build method ## 1.0.0-rc5 - Option for overlays to be already visible on the GameWidget diff --git a/doc/game.md b/doc/game.md index 98b8a57f5c6..a1d944e0dfe 100644 --- a/doc/game.md +++ b/doc/game.md @@ -27,14 +27,17 @@ class MyGameSubClass extends Game { main() { + final myGame = MyGameSubClass(); runApp( GameWidget( - game: MyGameSubClass(), + game: myGame, ) ); } ``` +**Note:** Do not instantiate your game in a build method. Instead create an instance of your game and reference it within your widget structure. Otherwise your game will be rebuild every time the Flutter tree gets rebuild. + It is important to notice that `Game` is an abstract class with just the very basic implementations of the gameloop. As an option and more suitable for most cases, there is the full-featured `BaseGame` class. For example, Forge2D games uses `Forge2DGame` class; diff --git a/lib/src/game/game_widget.dart b/lib/src/game/game_widget.dart index 6e157e8f578..f03585ae2a0 100644 --- a/lib/src/game/game_widget.dart +++ b/lib/src/game/game_widget.dart @@ -99,7 +99,7 @@ class GameWidget extends StatefulWidget { /// ``` const GameWidget({ Key key, - this.game, + @required this.game, this.textDirection, this.loadingBuilder, this.errorBuilder, From 9ab1bb4d798a1d56dddb19299e8f6d99e49775a0 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Wed, 20 Jan 2021 18:52:49 +0100 Subject: [PATCH 2/2] Removed entry from CHANGELOG --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ab3a8fd98..8150c652438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,6 @@ - Move files to comply with the dart package layout convention - Fix gesture detection bug of children of `PositionComponent` - The `game` argument on `GameWidget` is now required - - Added a note to the `GameWidget` docs mentioning to not instantiate inside a build method ## 1.0.0-rc5 - Option for overlays to be already visible on the GameWidget