AS3 - 如何绘制和对齐圆?

问题描述 投票:0回答: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
actionscript-3
3个回答
5
投票
drawCircle((stage.stageWidth - 100) / 2, (stage.stageHeight - 100) / 2, 100);

drawCircle的前两个参数是圆的center的X和Y位置,而不是圆的左上角位置。

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

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

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 属性放置它是一种更好的方法。假设你想移动那个圆圈?试图找出偏移量将是一场噩梦。


0
投票
    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;
© www.soinside.com 2019 - 2024. All rights reserved.