Actionscript Bitmap(或BitmapData)很奇怪。默认情况下,它的cacheAsBitmap不仅是假的,但似乎BitmapData实际上并不只是一个位图!
我发现,动画文字线alpha会让它们眨眼。我尝试以多种方式解决它,其中一种方法是使用背景绘制带有位图的文本并为位图设置动画:
package
{
import flash.events.Event;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
public class Main extends Sprite
{
private var bdata1:BitmapData = new BitmapData ( 150, 50, false, 0xDDDDFF );
private var bitmap1:Bitmap = new Bitmap( bdata1 );
private var bdata2:BitmapData = new BitmapData ( 100, 100, false, 0x00FFFF );
private var bitmap2:Bitmap = new Bitmap ( bdata2 );
private var show:Boolean = false;
public function Main():void
{
stage.frameRate = 1;
var tf:TextField = new TextField ();
tf.text = "layer top";
bdata1.draw( tf );
tf.text = "layer bottom"
bdata2.draw ( tf );
//*
bitmap1.cacheAsBitmap = true;
bitmap2.cacheAsBitmap = true;
//*/
addChild ( bitmap2 );
addChild ( bitmap1 );
addEventListener (Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame ( e:Event ):void
{
if ( show ) var diff:Number = .2;
else diff = -.2;
bitmap1.alpha += diff;
if ( bitmap1.alpha >= 1 ) {
show = false;
bitmap1.alpha = 1;
}
else if ( bitmap1.alpha <= 0 ) {
show = true;
bitmap1.alpha = 0;
}
}
}
}
它应该做的是在“图层底部”和“图层顶部”文本之间顺利(好吧,如果您更改FPS)转换。它的作用很奇怪,至少在我的机器上,清楚地表明位图中的文本不被视为位图,但仍然是矢量(可能是TextLine)。那么BitmapData只是模拟位图吗?这是一个错误吗?我错过了什么吗?
答案 0 :(得分:3)
首先,您需要在swf中嵌入Font
。假设您已嵌入"Arial"
。然后试试这个:
var tf:TextField = new TextField ();
var tf_format:TextFormat = tf.defaultTextFormat;
tf_format.font = "Arial"; //Specifying embedded font's name
tf.defaultTextFormat = tf_format;
tf.embedFonts = true;
tf.antiAliasType = AntiAliasType.ADVANCED;
//.........
在此之后,您将获得平滑的文字&#39;。