英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论