AS3 向显示对象添加边框
我知道如何绘制一个矩形并将其添加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将创建一个透明填充形状并将其添加到 DisplayObject,如下所示:
编辑:直接绘制到 DisplayObject
I would create a transparent fill shape and add it to the DisplayObject like this:
Edit :drawing directly to the DisplayObject
向某些内容添加边框的一个简单方法是使用 发光滤镜:
您可以玩这个在线演示。单击绿色圆圈可切换发光边框。
请记住,如果在大量项目上使用过滤器,可能会降低性能。
a simple way to add a border to something is to use a Glow Filter:
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.
我认为,如果您被迫使用 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?