如何使用 Flutter Flame 更改 TextComponent 中文本的大小?

问题描述 投票:0回答:1

如何更改Flame中TextComponent中文本的大小?我想让文字变大

我使用 Flame 文档来获取此内容,但我不知道如何修改它以获得更大的文本大小(例如 20pt 与 14pt)。另外,锚是什么?

final style = TextStyle(color: BasicPalette.darkBlue.color);
final regular = TextPaint(style: style);

TextComponent startText = TextComponent(text: 'test text', textRenderer: regular)
  ..anchor = Anchor.topCenter
  ..x = (width * 0.2)
  ..y = (height - (height*0.5))
  ..priority = 300;
flutter dart text flame
1个回答
1
投票
final style = TextStyle(
  color: BasicPalette.darkBlue.color,
  fontSize: 20.0, // Change the font size here
);
final regular = TextPaint(style: style);

TextComponent startText = TextComponent(
  text: 'test text',
  textRenderer: regular,
)
  ..anchor = Anchor.topCenter
  ..x = (width * 0.2)
  ..y = (height - (height * 0.5))
  ..priority = 300;

锚点是什么?

Flame 的 TextComponent 中的锚确定文本相对于其给定坐标(x 和 y)的位置。您可以从左上、中上、右上、左中、居中、右中、左下、中下和右下等选项中进行选择,以根据需要对齐文本。调整锚点和位置值以根据需要定位文本。

© www.soinside.com 2019 - 2024. All rights reserved.