Possibility to initialize all PositionComponents from onLoad (#1113)

* Fix ParallaxComponent constructor

* Fix sizing bug parallax_component

* Unify TextComponent and TextBoxComponent

* Fix tests

* Update PositionComponent docs

* Add changelog entry

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Fix analyze issue

* Apply suggestions from code review

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Fix line length in components.md

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Luan Nico <luanpotter27@gmail.com>
This commit is contained in:
Lukas Klingsbo
2021-11-18 11:42:12 +01:00
committed by GitHub
parent f777e1a0ea
commit 12fd07e5ae
20 changed files with 197 additions and 120 deletions

View File

@ -30,7 +30,7 @@ final _shaded = TextPaint(
class MyTextBox extends TextBoxComponent {
MyTextBox(String text)
: super(
text,
text: text,
textRenderer: _box,
boxConfig: TextBoxConfig(
maxWidth: 400,
@ -52,26 +52,26 @@ class TextGame extends FlameGame {
Future<void> onLoad() async {
await super.onLoad();
add(
TextComponent('Hello, Flame', textRenderer: _regular)
TextComponent(text: 'Hello, Flame', textRenderer: _regular)
..anchor = Anchor.topCenter
..x = size.x / 2
..y = 32.0,
);
add(
TextComponent('Text with shade', textRenderer: _shaded)
TextComponent(text: 'Text with shade', textRenderer: _shaded)
..anchor = Anchor.topRight
..position = size - Vector2.all(100),
);
add(
TextComponent('center', textRenderer: _tiny)
TextComponent(text: 'center', textRenderer: _tiny)
..anchor = Anchor.center
..position.setFrom(size / 2),
);
add(
TextComponent('bottomRight', textRenderer: _tiny)
TextComponent(text: 'bottomRight', textRenderer: _tiny)
..anchor = Anchor.bottomRight
..position.setFrom(size),
);