From 1f021b012ca5b410ef8b10d3acafdd3dedb41002 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Sun, 10 May 2020 18:49:30 +0200 Subject: [PATCH] Update outdated TextConfig docs --- docs/text.md | 10 ++++++++-- lib/text_config.dart | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/text.md b/docs/text.md index df4e071d0..41a66ed32 100644 --- a/docs/text.md +++ b/docs/text.md @@ -4,12 +4,12 @@ Flame has some dedicated classes to help you render text. # TextConfig -A Text Config contains all typographical information required to render texts; i.e., font size and color, family, etc. +A Text Config contains all typographical information required to render text; i.e., font size and color, family, etc. Example usage: ```dart -const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font', anchor: Anchor.rightBottom); +const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font'); ``` * fontFamily : a commonly available font, like Arial (default), or a custom font added in your pubspec (see [here](https://flutter.io/custom-fonts/) how to do it) @@ -24,6 +24,12 @@ After the creation of the config you can use its `render` method to draw some st config.render(canvas, "Flame is awesome", Position(10, 10)); ``` +If you want to set the anchor of the text you can also do that in the render call, with the optional parameter `anchor`: + +```dart +config.render(canvas, "Flame is awesome", Position(10, 10), anchor: Anchor.topCenter); +``` + ## Text Components Flame provides two text components that make it even easier to render text in your game: `TextComponent` and `TextBoxComponent`. diff --git a/lib/text_config.dart b/lib/text_config.dart index 7e935651b..9f9bdcfa8 100644 --- a/lib/text_config.dart +++ b/lib/text_config.dart @@ -70,8 +70,8 @@ class TextConfig { /// /// Example usage: /// - /// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font', anchor: Anchor.rightBottom); - /// config.render(c, Offset(size.width - 10, size.height - 10); + /// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font'); + /// config.render(c, Offset(size.width - 10, size.height - 10, anchor: Anchor.bottomRight); void render(Canvas canvas, String text, Position p, {Anchor anchor = Anchor.topLeft}) { final material.TextPainter tp = toTextPainter(text);