TextFormat 和 TextFields 在 FlashPlayer 外部显示不同
我一直在使用这样的 TextFields 来渲染游戏的文本。我一直在FlashDevelop中开发,所以SWF是使用Flex编译器编译的。
我的问题是,当我在浏览器中查看此文本时,它没有以适当的格式显示,而不是在 Flashplayer 中(看起来不错)。不同的屏幕分辨率在浏览器中扭曲文本的方式往往会有所不同。为什么会这样呢?
var welcomeText:TextField = new TextField();
//formatText creates a TextFormat object, sets those values into TextFormat
//then returns after doing TextField.defaultTextFormat = TextFormatObj;
formatText(welcomeText, 3, 0xFFFFFF, "Courier");
welcomeText.width = 385;
welcomeText.height = 25;
welcomeText.x = 60;
welcomeText.y = 60;
welcomeText.text = "Cogito ergo sum";
I have been using TextFields like this to render text for a game. I've been developing in FlashDevelop, so the SWF is compiled using the Flex compiler.
My problem is that this text is not displayed with the appropriate formatting when I view it inside the browser as opposed to a flashplayer (which looks fine). Different screen resolutions tend to vary in how they distort text in the browser. Why could this be?
var welcomeText:TextField = new TextField();
//formatText creates a TextFormat object, sets those values into TextFormat
//then returns after doing TextField.defaultTextFormat = TextFormatObj;
formatText(welcomeText, 3, 0xFFFFFF, "Courier");
welcomeText.width = 385;
welcomeText.height = 25;
welcomeText.x = 60;
welcomeText.y = 60;
welcomeText.text = "Cogito ergo sum";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生这种情况很可能是因为您没有嵌入字体。相反,您使用的是系统(或浏览器)可用的 Courier 字体。虽然这可以节省文件大小(字体未打包在 SWF 中),但它看起来并不总是那么好。
为了使用嵌入字体,您需要做两件事
1。将 TextField 的“embedFonts”设置为 true
2.嵌入字体
您可以在 AS3 中使用元数据来嵌入字体文件,如下所示:
注意:您还可以在 Flash Professional 库中创建字体链接。在库中,选择“新字体...”,为其命名。完成后,右键单击字体并选择“链接...”为其指定类名称(例如“Courier_Font”)并导出为 SWC。将其添加到 IDE 中的类路径中,然后就可以像这样访问该字体:
This is most likely happening because you are not embedding the font. Instead, you are using the Courier font available to they system (or browser). While this saves on file-size (the font is not packaged within the SWF), it doesn't always look so great.
In order to use an embedded font, you need to do 2 things
1. Set "embedFonts" to true for your TextField
2. Embed the font
You can use meta data in your AS3 to embed the font file like this:
Note: You can also create a font linkage in the library of Flash Professional. In the library, select "New Font...", name it. When done, right-click the font and select "Linkage..." give it a class name (say "Courier_Font")and export as a SWC. Add this to your class-path in your IDE and the font will be accessible like this:
尝试看看这个 。我知道我过去在格式化方面遇到了麻烦,所以我像您一样设置了一个 TextFormat 对象,而且我
也使用了该命令。您可以通过 SetStyle 设置很多参数(字体系列、颜色,甚至文本格式),与此示例类似......
希望这会有所帮助。我猜想尽可能多地设置它。
Try to take a look at this. I know I've had trouble in the past with formatting so I set a TextFormat object just as you do plus I use the
command as well. You can set a lot of parameters through SetStyle (font family, color, even text format) similar to this example...
Hopefully this helps. Just try to set it as many ways as possible I guess.