我正在尝试将 Sprite 转换为 Bitmap(首先从 Sprite 创建 BitMapData),但无论我做什么,Bitmap 似乎都没有出现。
public class Platform
{
private var startingPointX:Number;
private var startingPointY:Number;
private var length:Number;
private var platformLine:Sprite;
private var color:uint;
private var platformBitmap:Bitmap;
private var platformBitmapData:BitmapData;
public function Platform(stage:Stage, startX:Number, startY:Number, len:Number, theColor:uint)
{
startingPointX = startX;
startingPointY = startY;
length = len;
color = theColor;
platformLine = new Sprite();
platformLine.graphics.lineStyle(5, color);
platformLine.graphics.moveTo(startingPointX, startingPointY);
platformLine.graphics.lineTo(startingPointX + length, startingPointY);
platformBitmapData = new BitmapData(platformLine.width, platformLine.height);
platformBitmapData.draw(platformLine);
platformBitmap = new Bitmap(platformBitmapData);
//stage.addChild(platformLine);
stage.addChild(platformBitmap);
}
}
是的,我进口了所有东西。一切运行没有错误。
Sprite 本身(我在上面称为 platformLine)能够显示(参见上面的注释行)。但是,stage.addChild(platformBitmap) 不会在舞台上显示任何内容。使用 beginFill 和 endFill 方法似乎并没有改变任何东西。
我查看了各种关于将 Sprites 转换为 Bitmaps 的网站,他们都说使用 BitmapData 的 draw 方法来做到这一点。
所以我的问题是......为什么 platformBitmap 最终对我来说是“空白”?