mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-04 04:47:13 +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
|
# 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:
|
Example usage:
|
||||||
|
|
||||||
```dart
|
```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)
|
* 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));
|
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
|
## Text Components
|
||||||
|
|
||||||
Flame provides two text components that make it even easier to render text in your game: `TextComponent` and `TextBoxComponent`.
|
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:
|
/// Example usage:
|
||||||
///
|
///
|
||||||
/// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font', anchor: Anchor.rightBottom);
|
/// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font');
|
||||||
/// config.render(c, Offset(size.width - 10, size.height - 10);
|
/// config.render(c, Offset(size.width - 10, size.height - 10, anchor: Anchor.bottomRight);
|
||||||
void render(Canvas canvas, String text, Position p,
|
void render(Canvas canvas, String text, Position p,
|
||||||
{Anchor anchor = Anchor.topLeft}) {
|
{Anchor anchor = Anchor.topLeft}) {
|
||||||
final material.TextPainter tp = toTextPainter(text);
|
final material.TextPainter tp = toTextPainter(text);
|
||||||
|
|||||||
Reference in New Issue
Block a user