Actionscript Bitmap(或 BitmapData)很奇怪。不仅它的 cacheAsBitmap 默认为 false,而且 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 是否仅模拟位图?它是一个错误吗?我错过了什么吗?