开发者

ActionScript - Masking Parent of Dynamic Text Removes Anti-Alias?

when adding a mask to a parent sprite with a dynamic text field, the text loses anti-aliasing. how can i maintain the text's anti-alias while still applying a mask to its parent, and subsequently to itself.

the font is embedded, and the text field will be animated so it must also be masked along with its parent.

ActionScript - Masking Parent of Dynamic Text Removes Anti-Alias?

package
{   
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.*;

public class Test extends Sprite
    {
    public funct开发者_开发百科ion Test()
        {
        //Create Background Canvas
        var canvas:Sprite = new Sprite();
        canvas.graphics.beginFill(0xFF0000)
        canvas.graphics.drawRect(0, 0, 100, 100);

        //Create Dynamic Text
        var field:TextField = new TextField();
        field.width = 100;
        field.autoSize = TextFieldAutoSize.LEFT;
        field.selectable = false;
        field.text = "Dynamic\nText";

        var format:TextFormat = new TextFormat();
        format.font = "Myriad Pro";
        format.color = 0xFFFFFF;
        format.size = 14;
        field.setTextFormat(format);

        //Add Dynamic Text To Background Canvas
        field.x = canvas.width /2  - field.width / 2;
        field.y = canvas.height / 2 - field.height / 2;
        canvas.addChild(field);

        //Create Mask
        var canvasMask:Shape = new Shape();
        canvasMask.graphics.beginFill(0);
        canvasMask.graphics.drawRoundRect(0, 0, 100, 100, 50);

        //Add Background Canvas And Mask To Display List
//      canvas.mask = canvasMask;
//      addChild(canvasMask);
        addChild(canvas);
        }
    }
}


It seems this has to do with the way the TextField is cached as a Bitmap when you apply the mask. Actually I was able to reproduce the same behavior simply by toggling the cacheAsBitmap property on the TextField.

Adding these lines seem to solve the problem.

    field.embedFonts = true;
    field.antiAliasType = AntiAliasType.ADVANCED;
    //you can adjust the thickness & sharpness if needed
    field.thickness = 200;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜