问题描述
我有一些用户可以操作、拖动和调整大小的精灵.现在我希望能够在这些精灵中显示文本.我已经尝试了很多,可能是愚蠢的方法.就像从 Label 继承并将 Label 子级添加到精灵一样,但没有显示文本.
I have some sprites that the users can manipulate, drag around and resize. Now I'd like to be able to display text in those sprites. I've tried lots of, probably stupid, ways. Like inheriting from Label and adding a Label child to the sprite, but no text shows up.
一件令人不安的事情:从 Label 继承,如果我在调试器中运行并检查我的 Label 子类实例,我会得到文本显示.
One disturbing thing: Inheriting from Label I get the text to show up if I run in the debugger and inspect my Label subclass instance.
我有一种感觉,我错过了一些非常明显的东西.这是怎么做的,正确的方法?
I have this feeling I'm missing something really obvious. How is this done, the proper way?
推荐答案
我会选择比 Label 更底层的东西.使用 TextField 并将其作为子项添加到 Sprite:
I would go with something more low-level than Label. Use a TextField and add it as a child to the Sprite:
var text:TextField = new TextField();
text.text = "hello world";
addChild(text);
注意:如果旋转 Sprite 并且未嵌入字体,您的文本将不会显示.
Note: your text will not show up if the Sprite is rotated and the fonts are not embedded.
这篇关于如何在 ActionScript 3 精灵中绘制文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!