如何使用图形对象在边框容器内绘制圆形?
我的基本要求是在布局设置为 BasicLayout 的 BorderContainer
内绘制一个圆圈。
我在 BorderContainer 对象的 CREATION_COMPLETE
事件中运行此方法。
this.graphics.beginFill(0xff0000);
this.graphics.lineStyle(1, 0x00ff00);
this.graphics.drawCircle(0, 0, 50);
this.graphics.endFill();
抱歉直言不讳,但为什么我什么也没看到?我知道我一定错过了一些非常基本的东西。我可以像这样画画还是应该在其他活动中画画?
PS:我知道我可以创建一个椭圆对象并轻松地将其添加到边框容器中,但我想知道如何使用图形对象来做到这一点。
My basic requirement is to draw a circle inside a BorderContainer
with the layout set to BasicLayout
I run this method in the CREATION_COMPLETE
event of the BorderContainer object.
this.graphics.beginFill(0xff0000);
this.graphics.lineStyle(1, 0x00ff00);
this.graphics.drawCircle(0, 0, 50);
this.graphics.endFill();
Sorry to be blunt, but why don't I see anything? I know I must be missing something VERY basic here. Can I just draw like this OR should I draw in some other event?
P.S: I know that I can create a Ellipse object and easily add it to the border container but I would like to know how I can do this using the graphics object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回到过去,您可以覆盖 updateDisplayList 并在那里进行此类绘图。我猜想在创建完成后的某个时刻事情会得到刷新。由于您正在绘制而不是向舞台添加对象,因此您的圆圈实际上并不是任何生命周期的一部分,并且每当显示列表被弄脏/重绘时都会被擦除干净。希望有帮助。
Back in the olden days you would override updateDisplayList and do this sort of drawing there. I'm guessing things are getting refreshed at some point AFTER creation complete. Since you are drawing rather than adding an object to the stage, your circle isn't really part of any kind of lifecycle and will get wiped clean whenever the display list is dirtied/redrawn. Hope that helps.
我看到两个可能的问题。
对舞台的反对
边框容器对象。尝试追踪
这个在你的事件监听器中,或者
将其更改为 target 或 currentTarget
I see two possible problems.
object to the stage
BorderContainer object. Try to trace
this in your event listner, or
change it to target or currenTarget
使用上面的代码将在屏幕上显示一个矩形。
Using the above code will show a rectangle on your screen.