需求:需要在死亡人物处实现一个3D的倒计时
问题:如果用两个以上的Sprite3D实现,因为是billboard,总会有一个视角是重叠的
解决:将要显示的图片资源先合并,然后再替换Sprite3D的material
代码
var num0:int = value / 10;
var num1:int = value % 10;
_bitMapData ||= new BitmapData(64, 32, true, 0x00FFFFFF);
_emptyBmp ||= new BitmapData(19, 26, true, 0x00FFFFFF);
_rect ||= new Rectangle(0, 0, 19, 26);
_point ||= new Point();
if(_lastNum0 != num0){
_lastNum0 = num0;
bmp = asset.getBitmapDataByName(num0 + ".png");
_point.x = 0;
_bitMapData.copyPixels(_emptyBmp, _rect, _point);//先清空
_bitMapData.copyPixels(bmp, _rect, _point); }
if(_lastNum1 != num1){
_lastNum1 = num1;
bmp = asset.getBitmapDataByName(num1 + ".png");
_point.x = 25;
_bitMapData.copyPixels(_emptyBmp, _rect, _point);
_bitMapData.copyPixels(bmp, _rect, _point);
}
(sp.material as TextureMaterial).texture.dispose();
(sp.material as TextureMaterial).texture = Cast.bitmapTexture(bitMapData);
如果想添加文字
则用 bitmapData.draw(new TextField);
可以用来实现怪物跟随的名字等信息