2

円を描いて中心に揃えたい。私のコードはそれをしません:

var circle:Shape = new Shape(); // The instance name circle is created
circle.graphics.beginFill(0x990000, 1); // Fill the circle with the color 990000
circle.graphics.lineStyle(2, 0x000000); // Give the ellipse a black, 2 pixels thick line
circle.graphics.drawCircle((stage.stageWidth - 100) / 2, (stage.stageHeight - 100) / 2, 100); // Draw the circle, assigning it a x position, y position, raidius.
circle.graphics.endFill(); // End the filling of the circle
addChild(circle); // Add a child
4

2 に答える 2

5
drawCircle((stage.stageWidth - 100) / 2, (stage.stageHeight - 100) / 2, 100);

drawCircleの最初の 2 つのパラメーターは、円の左上の位置ではなく、円の中心の X および Y 位置です。

円をステージの中心に配置したい場合は、円の中心を同じ位置に配置するだけでよいため、次のように drawCircle を呼び出します。

drawCircle(stage.stageWidth / 2, stage.stageHeight / 2, 100);
于 2012-12-26T22:52:28.527 に答える
4

あなたのアプローチはうまくいくと思いますが、あなたの形での作業が少し難しくなります.

このアプローチを検討してください:

var circle:Shape = new Shape();
circle.graphics.clear();
circle.graphics.lineStyle(2,0x000000);
circle.graphics.beginFill(0x990000);
circle.graphics.drawCircle(0,0,100);
circle.graphics.endFill();
addChild(circle);
circle.x = stage.stageWidth / 2;
circle.y = stage.stageHeight/ 2;

シェイプの 0,0 の位置を中心に円を描画し、x および y プロパティを介して配置する方がはるかに優れたアプローチです。その円を移動したいとしますか? オフセットを把握しようとするのは悪夢です。

于 2012-12-27T04:18:29.867 に答える