TextFormat 和 TextFields 在 FlashPlayer 外部显示不同

发布于 2025-01-05 08:37:53 字数 650 浏览 0 评论 0原文

我一直在使用这样的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若无相欠,怎会相见 2025-01-12 08:37:53

发生这种情况很可能是因为您没有嵌入字体。相反,您使用的是系统(或浏览器)可用的 Courier 字体。虽然这可以节省文件大小(字体未打包在 SWF 中),但它看起来并不总是那么好。

为了使用嵌入字体,您需要做两件事

1。将 TextField 的“embedFonts”设置为 true

welcomeText.embedFonts = true;

2.嵌入字体

您可以在 AS3 中使用元数据来嵌入字体文件,如下所示:

[Embed(source="C:\WINDOWS\Fonts\COURIER.TTF", fontFamily="Courier")]
var _courier:String;
myTextFormat.font = _courier;

注意:您还可以在 Flash Professional 库中创建字体链接。在库中,选择“新字体...”,为其命名。完成后,右键单击字体并选择“链接...”为其指定类名称(例如“Courier_Font”)并导出为 SWC。将其添加到 IDE 中的类路径中,然后就可以像这样访问该字体:

var _font:Courier_Font = new Courier_Font();
myTextFormat.font = _font.fontName;

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

welcomeText.embedFonts = true;

2. Embed the font

You can use meta data in your AS3 to embed the font file like this:

[Embed(source="C:\WINDOWS\Fonts\COURIER.TTF", fontFamily="Courier")]
var _courier:String;
myTextFormat.font = _courier;

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:

var _font:Courier_Font = new Courier_Font();
myTextFormat.font = _font.fontName;
素染倾城色 2025-01-12 08:37:53

尝试看看这个 。我知道我过去在格式化方面遇到了麻烦,所以我像您一样设置了一个 TextFormat 对象,而且我

testfield.SetStyle()

也使用了该命令。您可以通过 SetStyle 设置很多参数(字体系列、颜色,甚至文本格式),与此示例类似......

TextFormat textStyle;
// Set properties for textstyle
textField.setStyle("textFormat", textStyle);

希望这会有所帮助。我猜想尽可能多地设置它。

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

testfield.SetStyle()

command as well. You can set a lot of parameters through SetStyle (font family, color, even text format) similar to this example...

TextFormat textStyle;
// Set properties for textstyle
textField.setStyle("textFormat", textStyle);

Hopefully this helps. Just try to set it as many ways as possible I guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文