Talking about Actionscript 3 and Flash.
Since I think devlopers’ attention will focus on mobile game developement during these days, let’s see a feature that will let you use fonts in a way that will successfully adapt across devices, as introduced in the Authoring mobile Flash content for multiple screen sizes guide.
FTE (Flash Text Engine)
The FTE provides low-level support for sophisticated control of text metrics, formatting, and bidirectional text. It was primarily designed as a foundation for developers to create text-handling components, but in this simple example I’ll use it like a normal text field to see if I can improve its readability.
This example is intended to be ran on Flash Player 10
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.engine.*;
public class fte extends Sprite {
public function fte():void {
// FTE TEXT
var font_description:FontDescription = new FontDescription();
font_description.fontName="Verdana";
font_description.fontWeight=FontWeight.BOLD;
font_description.fontPosture=FontPosture.ITALIC;
font_description.renderingMode=RenderingMode.CFF;
font_description.locked=true;
var element_format:ElementFormat=new ElementFormat(font_description);
element_format.fontSize=40;
element_format.kerning=Kerning.ON;
element_format.color=0x000000;
element_format.alpha=1;
var text_element:TextElement=new TextElement("Hello Flash World",element_format);
var text_block:TextBlock = new TextBlock();
text_block.content=text_element;
var text_line:TextLine=text_block.createTextLine(null,500);
text_line.x=20;
text_line.y=40;
addChild(text_line);
// NORMAL TEXT
var text_field:TextField=new TextField();
var text_format:TextFormat = new TextFormat();
text_format.color=0x000000;
text_format.size=40;
text_format.bold=true;
text_format.font="Verdana";
text_format.italic=true;
text_field.x=18;
text_field.y=30;
text_field.width=460;
text_field.height=60;
text_field.text="Hello Flash World";
text_field.setTextFormat(text_format);
addChild(text_field);
}
}
}
Line 5: importing the required library
Lines 9-14: using FontDescription
class to represent the font. As you can see in the official docs, locking the font (line 14) and setting the rendering mode to CFF
(line 13) shoud make the text more legible, especially at small sizes
Lines 15-19: using ElementFormat
class to set formatting information. As described in the docs the only interesting feature I did not use was the baseline alignment. Turning off the kerning (line 17) should improve readability
Line 20: using TextElement
class to declare the string of formatted text I am about to display. No fancy features here according to the docs
Lines 21-22: TextBlock
class is the renderer itself, but it’s more about formatting and management than rendering, according to the docs
Lines 23-25: using TextLine
class to display the content. According to the docs, it just has a lot of read only properties.
Lines 28-40: doing the same thing with old text fields.
And this is the result:
The upper line is made using FTE, the lower one with normal text fields.
I have to say I don’t see noticeable improvements, anyway it will introduce you into FTE world.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.