在 AS3 中维护两点之间的 lineTo 最有效的方法是什么?

发布于 2024-11-05 19:22:46 字数 380 浏览 1 评论 0原文

我正在寻找一种最有效的方法来维持 AS3 中两点与一条线的连接。基本上,我有一大堆四处移动的圆圈,并且有一个属性 subNode ,它将充当线条的终点。

目前,我的做法非常密集:

if(_line != null) _line.parent.removeChild(_line);

_line = new Sprite();
_line.graphics.lineStyle(1, 0xE1164B);
_line.graphics.lineTo(subNode.x - x, subNode.y - y);

addChild(_line);

是否可能只是一个 redrawLine() 或者我缺少的东西?

I'm looking to work out the most efficient way to maintain the joining of two points with a line in AS3. Basically, I have a whole bunch of circles that move around, and have a property subNode which will act as an end point for the line.

At the moment, the way I'm doing it is extremely intensive:

if(_line != null) _line.parent.removeChild(_line);

_line = new Sprite();
_line.graphics.lineStyle(1, 0xE1164B);
_line.graphics.lineTo(subNode.x - x, subNode.y - y);

addChild(_line);

Is there maybe just a redrawLine() or something that I'm missing?

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

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

发布评论

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

评论(1

嘿哥们儿 2024-11-12 19:22:46

您不必每次都实例化 Sprite。在这种情况下,Shape 也应该足够了。

if(_line == null) {
   _line = addChild(new Shape()) as Shape;
}

_line.graphics.clear();
_line.graphics.lineStyle(1, 0xE1164B);
_line.graphics.lineTo(subNode.x - x, subNode.y - y);

您还应该考虑何时划清界限。也许只有当子节点移动时。但没有足够的代码来正确回答这个问题。

You don't have to instantiate a Sprite every time. Also a Shape should be enough in this case.

if(_line == null) {
   _line = addChild(new Shape()) as Shape;
}

_line.graphics.clear();
_line.graphics.lineStyle(1, 0xE1164B);
_line.graphics.lineTo(subNode.x - x, subNode.y - y);

Also you should think about when to draw the line. Maybe only if the subNode hase moved. But there is not enough code for a proper answer to that.

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