AS3 - 如何绘制和对齐圆?

nik*_*kel 2 actionscript-3

我想绘制一个圆圈并将其对齐居中.我的代码不这样做:

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
Run Code Online (Sandbox Code Playgroud)

pok*_*oke 5

drawCircle((stage.stageWidth - 100) / 2, (stage.stageHeight - 100) / 2, 100);
Run Code Online (Sandbox Code Playgroud)

的前两个参数画圆是的X和Y位置中心的圆的,而不是圆形的左上位置.

如果你想让你的圆圈位于舞台的中心,你只需要将圆圈的中心放在同一个位置,这样就可以像这样调用drawCircle:

drawCircle(stage.stageWidth / 2, stage.stageHeight / 2, 100);
Run Code Online (Sandbox Code Playgroud)