0

オブジェクトの中心にスナップする線を作成する方法について質問があります。私の場合、ボタンが押されたときにいくつかの円を描き、別のボタンで線を追加しますが、それらを中心にスナップしたいので、円を移動すると、線が円を作成するコードを拡張/圧縮します:

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);
}

長い投稿で申し訳ありませんが、私は本当に助けが必要ですt know how to do it and have no ideas, it is a big project i.MaxFlowがどのように見えるかをシミュレートするために取り組んでい ます.円の中心へ…

4

1 に答える 1