mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Update outdated TextConfig docs
This commit is contained in:
10
docs/text.md
10
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`.
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user