我有一个关于如何使一条线捕捉到对象中心的问题,在我的情况下,我在按下按钮时画了一些圆圈,然后另一个按钮添加了线条,但我希望它们捕捉到中心,所以当我移动圆圈时,线条会扩展/压缩我创建圆圈的代码:
function new_sond(event:MouseEvent):void
{
if (i<9)
{
i++;
q=i;
var btn:Sprite = new Sprite();
btn.graphics.beginFill(0x0099FF, 1);
btn.graphics.drawCircle(400, 300, 15);
btn.graphics.endFill();
var s:String = String(q);
btn.name=s;
var textField = new TextField();
textField.mouseEnabled=false;
textField.text = i;
textField.width = 10;
textField.height = 17;
textField.x = 395; // center it horizontally
textField.y = 292; // center it vertically
btn.addChild(textField);
this.addChild(btn);
}}
我从一个圆圈画到另一个圆圈的代码
function click1(e:MouseEvent):void{
e.currentTarget.removeEventListener(MouseEvent.CLICK, click1);
if (e.target.name!=null ){
cntr=cntr+1;
trs=e.target.name;
var trn = Number(trs);
du[cntr]=trn;
sx=e.target.x+400;
sy=e.target.y+300;
stage.addEventListener(MouseEvent.CLICK,click2);
}
}
function click2(e:MouseEvent):void{
e.currentTarget.removeEventListener(MouseEvent.CLICK, click2);
fx=e.target.x+400;
fy=e.target.y+300;
var i:int;
i=2;
trs=e.target.name;
var trn = Number(trs);
u[cntr]=trn;
var line:Shape = new Shape();
line.graphics.lineStyle(1,0xFF0000,2);
line.graphics.moveTo(sx,sy);
line.graphics.lineTo(fx,fy);
this.addChild(line);
var inputField:TextField = new TextField();
inputField.border = true;
inputField.type = TextFieldType.INPUT;
inputField.width = 23;
inputField.height = 18;
inputField.x = (sx+fx)/2;
inputField.y = (sy+fy)/2;
inputField.multiline = false;
inputField.maxChars = 3;
inputField.restrict = "0-9";
inputField.addEventListener(Event.CHANGE, checkInput);
addChild(inputField);
}
对不起,很长的帖子,但我真的需要一些帮助,我只是在努力模拟 MaxFlow 的外观: httpt know how to do it and have no ideas, it is a big project i
://gyazo.com/d0478d967b4cc34b59490245b3530e26
我只是想知道是否可以让线条捕捉到圆心...