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

huangapple go评论77阅读模式
英文:

How can I change the size of the text in TextComponent using Flutter Flame?

问题

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

我使用了Flame文档来获得这个信息,但我不知道如何修改文本大小(比如20pt与14pt的区别)。还有,锚点是什么?

final regular = TextPaint(style: style);

TextComponent startText = TextComponent(text: '测试文本', textRenderer: regular)
  ..anchor = Anchor.topCenter
  ..x = (宽度 * 0.2)
  ..y = (高度 - (高度*0.5))
  ..priority = 300;
英文:

How do you change the size of the text in the TextComponent in Flame? I want to make the text larger

I used the Flame documentation to get this, but I don't know how to modify it for a larger text size (like 20pt vs 14pt). Also, what is the anchor?

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;

答案1

得分: 1

final style = TextStyle(
  color: BasicPalette.darkBlue.color,
  fontSize: 20.0, // 在这里更改字体大小
);
final regular = TextPaint(style: style);

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

"What's anchor?"

在Flame的TextComponent中,"anchor"(锚点)决定了文本相对于给定坐标(x和y)的位置。您可以从选项中选择,如top-left(左上角),top-center(顶部居中),top-right(右上角),center-left(左侧居中),center(居中),center-right(右侧居中),bottom-left(左下角),bottom-center(底部居中)和bottom-right(右下角),以根据需要对齐文本。调整锚点和位置值以定位文本。

英文:
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;

What's anchor?

The anchor in Flame's TextComponent determines where the text is positioned relative to its given coordinates (x and y). You can choose from options like top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, and bottom-right to align the text as you want. Adjust the anchor and position values to position the text as needed.

huangapple
  • 本文由 发表于 2023年6月2日 02:48:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定