を描画します私はLATMを想定して、[1]とLATM [0]あなたが間に線を引くしようとしている2つの形状です。その場合、同じ点に行くために2つの線があることに気づいたか?
必要なものは次のとおりです。
spr.graphics.moveTo(latM[0].x, latM[0].y);
spr.graphics.lineTo(latM[1].x, latM[1].y);
どのように動作するかを示す小さなプロトタイプです。 (これは、それが迅速かつ汚いプロトタイプであるスーパーソリッドコードを意味するものではありません。)
package src
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var obj1:Sprite = new Sprite();
private var obj2:Sprite = new Sprite();
private var lineSprite:Sprite = new Sprite();
// for testing your line.
// we don't really need it for this prototype however it
// is being used since this is how your accessing your Objects.
private var latM:Array = [];
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, initMain);
}
private function initMain(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initMain);
obj1.graphics.lineStyle(1, 0);
obj1.graphics.beginFill(0xccccff);
obj1.graphics.drawCircle(0, 0, 20);
obj1.graphics.endFill();
obj1.x = 100;
obj1.y = 100;
obj2.graphics.lineStyle(1, 0);
obj2.graphics.beginFill(0xffcccc);
obj2.graphics.drawCircle(0, 0, 20);
obj2.graphics.endFill();
obj2.x = 400;
obj2.y = 200;
// for testing your line.
latM.push(obj1, obj2);
addChild(obj1);
addChild(obj2);
addChild(lineSprite);
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleEnterFrame(e:Event):void
{
// this will clear and redraw the line between the two sprites
// every frame and thus always be up to date.
lineSprite.graphics.clear();
lineSprite.graphics.lineStyle(2, 0xff0000);
lineSprite.graphics.moveTo(latM[0].x, latM[0].y);
lineSprite.graphics.lineTo(latM[1].x, latM[1].y);
//obj1.x++; // uncomment this line and you can watch it move and keep the line perfect.
}
}
}
あなたは、左下の方に傾く何を意味するのですか? –
私はそれを簡単にする例を挙げます:私はx100とy100から始まり、x200とx50の間に線を入れたいとしましょう。同じものを指していれば、左下を下向きにしますスポットを使ってx 20 y 500と言うことができます。同じ結果が得られます – JustAddX
Yを変更することで、ラインを「ポイントダウン」します。私は何かを逃していますか、これはあなたが探している望ましい効果ではありませんか? –