AS3 向显示对象添加边框

发布于 2024-11-17 18:26:26 字数 155 浏览 4 评论 0原文

我知道如何绘制一个矩形并将其添加到 DisplayObjectContainer, 但是您是否看到了直接向 DisplayObject 添加边框的更简单方法?

DisplayObject 似乎没有 addChild(),所以我必须将它添加到父级上,在我看来这并不完美......

I know how to draw a rectangle and add it to a DisplayObjectContainer,
but do you see a simpler method to directly add a border to a DisplayObject?

DisplayObject don't seem to have addChild(), so I would have to add it on the parent, which is not perfect in my opinion...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话墙 2024-11-24 18:26:26

我将创建一个透明填充形状并将其添加到 DisplayObject,如下所示:

编辑:直接绘制到 DisplayObject

this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(0x000000, 0);
this.graphics.drawRect(0, 0, 50, 50);
this.graphics.endFill();

I would create a transparent fill shape and add it to the DisplayObject like this:

Edit :drawing directly to the DisplayObject

this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(0x000000, 0);
this.graphics.drawRect(0, 0, 50, 50);
this.graphics.endFill();
远山浅 2024-11-24 18:26:26

向某些内容添加边框的一个简单方法是使用 发光滤镜

var _objectToBorder:Sprite = new Sprite();
// draw something or add something in the _objectToBorder
var glowFilter:GlowFilter = new GlowFilter(0x000000, 1, 6, 6, 20, 1);
_objectToBorder.filters = [glowFilter];

您可以玩这个在线演示。单击绿色圆圈可切换发光边框。

请记住,如果在大量项目上使用过滤器,可能会降低性能。

a simple way to add a border to something is to use a Glow Filter:

var _objectToBorder:Sprite = new Sprite();
// draw something or add something in the _objectToBorder
var glowFilter:GlowFilter = new GlowFilter(0x000000, 1, 6, 6, 20, 1);
_objectToBorder.filters = [glowFilter];

You can play with this online demo. Click on the green circle to toggle the glow border.

Keep in mind that using filters can mar performance if used on a ton of items.

云仙小弟 2024-11-24 18:26:26

我认为,如果您被迫使用 DisplayObject 而不是 DisplayObjectContainer,那么您没有太多选择,只能以一种或另一种方式将边框写入父级。不过,我同意,这不是一个很好的做事方式,我认为如果可能的话,更好的方法是不使用 DisplayObject。

编辑:您如何将其创建为 DisplayObject?你不能直接实例化displayObjects,那么这是DisplayObject的扩展还是某些东西的返回值?

I think that if you're forced to use DisplayObject rather than DisplayObjectContainer then you don't have much choice than to write your border to the parent one way or another. Agreed though, it's not a nice way of doing things and I think that if it's possible the better approach would be to not use DisplayObject.

Edit: How are you creating this as DisplayObject? You can't instantiate displayObjects directly, so is this an extension of DisplayObject or the return value of something?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文