在ActionScript绘制的形状文本3 [英] Draw text on shape in ActionScript 3

查看:149
本文介绍了在ActionScript绘制的形状文本3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法来绘制一个DisplayObject文本或形状只用动作?我可以在网上找到的唯一方法是通过创建一个文本字段,但我不能一个TF增加的DisplayObject或形状。

编辑:

解决了由于<一个href="http://stackoverflow.com/questions/2340525/draw-text-on-shape-in-actionscript-3/2340543#2340543">viatropos.

对于任何人的兴趣:

的DisplayObject 工具的IBitmapDrawable 可以作为参数传递给 A 的BitmapData 对象,然后可以使用绘制 graphics.beginBitmapFill 的功能。

  VAR文本框:文本字段=新的TextField;
的TextField.text =文本;

VAR的BitmapData:的BitmapData =新的BitmapData(theWidth,theHeight,真实,00000000);
的BitmapData.draw(文本框);

graphics.beginBitmapFill(的BitmapData);
graphics.drawRect(0,0,theWidth,theHeight);
graphics.endFill();
 

解决方案

好问题。这是超出了我曾经需要做的,但我想我知道如何做到这一点。

形状延伸的DisplayObject,但不是的DisplayObjectContainer,所以你可以什么也不会增加。但它的确实的有图形属性,这样你就可以借鉴的东西进去。我能想到的最好的办法是把文本字段的位图快照,并绘制成图形。我知道这是什么Degrafa做他们的 RasterText (检查出的<一个href="http://$c$c.google.com/p/degrafa/source/browse/branches/Origin/Degrafa/com/degrafa/geometry/RasterText.as"相对=nofollow>来源,它真的有用)。

如果你改变了你的形状到雪碧代替,这是一个容易得多。雪碧延伸的DisplayObjectContainer,所以你可以添加您的文本字段存在。

希望帮助, 兰斯

Is there any way to draw text in a DisplayObject or Shape using only ActionScript? The only way I can find on the web is by creating a TextField, but I can't add a TF to a DisplayObject or Shape.

Edit:

Solved thanks to viatropos.

For anyone that's interested:

DisplayObject implements IBitmapDrawable which can be passed as an argument to the draw function of a BitmapData object, which then can be drawn using graphics.beginBitmapFill.

var textfield:TextField = new TextField;
textfield.text = "text";

var bitmapdata:BitmapData = new BitmapData(theWidth, theHeight, true, 0x00000000);
bitmapdata.draw(textfield);

graphics.beginBitmapFill(bitmapdata);
graphics.drawRect(0, 0, theWidth, theHeight);
graphics.endFill();

解决方案

Good question. This is beyond anything I've ever needed to do, but I think I know how to do it.

Shape extends DisplayObject, but not DisplayObjectContainer, so you can't add anything to it. But it does have the graphics property, so you can draw things into it. The best way I can think of is to take a Bitmap snapshot of the TextField, and draw that into the Shape. I know this is what Degrafa does for their RasterText (check out the source, it's really helpful).

If you changed your Shape to a Sprite instead, it's a lot easier. Sprite extends DisplayObjectContainer, so you could add your TextField there.

Hope that helps, Lance

这篇关于在ActionScript绘制的形状文本3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆