Reputation: 39466
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?
Upvotes: 0
Views: 475
Reputation: 20230
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.
Upvotes: 2