Update outdated TextConfig docs

This commit is contained in:
Lukas Klingsbo
2020-05-10 18:49:30 +02:00
parent 6e2467b680
commit 1f021b012c
2 changed files with 10 additions and 4 deletions

View File

@ -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`.

View File

@ -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);