我试图让小圆圈能够在大圆圈内旋转。但我得到的是小圆圈在大圆圈外旋转。 这是我的代码:
import flash.events.Event;
import flash.events.MouseEvent;
var Rec:Number=-1;
stage.addEventListener(Event.ENTER_FRAME,EntFrame);
function EntFrame(e:Event):void
{
if (Rec == -1)
{
CircleL.rotation-= 2;
}
}
var cenX = CircleL.x;
var cenY = CircleL.y;
var ccStep = .01;
var twoPI = 2 * Math.PI;
var circleSNum1:Number = Math.random();
var circleSNum2:Number = Math.random();
var circleSNum3:Number = Math.random();
var circleSNum4:Number = Math.random();
var circleSNum5:Number = Math.random();
function randomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
var radius1 = randomRange(10, 90);
var radius2 = randomRange(10, 90);
var radius3 = randomRange(10, 90);
var radius4 = randomRange(10, 90);
var radius = randomRange(10, 90);
function move(event:Event):void
{
CircleL.CircleS1.x = cenX + Math.cos(circleSNum1 * twoPI) * radius;
CircleL.CircleS1.y = cenY + Math.sin(circleSNum1 * twoPI) * radius;
CircleL.CircleS2.x = cenX + Math.cos(circleSNum2 * twoPI) * radius2;
CircleL.CircleS2.y = cenY + Math.sin(circleSNum2 * twoPI) * radius2;
CircleL.CircleS3.x = cenX + Math.cos(circleSNum3 * twoPI) * radius3;
CircleL.CircleS3.y = cenY + Math.sin(circleSNum3 * twoPI) * radius3;
CircleL.CircleS4.x = cenX + Math.cos(circleSNum4 * twoPI) * radius4;
CircleL.CircleS4.y = cenY + Math.sin(circleSNum4 * twoPI) * radius4;
CircleL.CircleS5.x = cenX + Math.cos(circleSNum5 * twoPI) * radius1;
CircleL.CircleS5.y = cenY + Math.sin(circleSNum5 * twoPI) * radius1;
}
addEventListener(Event.ENTER_FRAME,move);
以下是我运行时的样子:
答案 0 :(得分:1)
问题很可能就是您的圈子嵌套以及如何进行计算。
.x
属性的.y
和DisplayObject
始终与父级的来源有关。看看你的代码:
CircleL.CircleS1
CircleL.CircleS2
所有较小的圆圈都有较大的圆圈作为容器。但是你的计算是:
cenX + Math.cos(circleSNum1 * twoPI) * radius;
// aka
CircleL.x + Math.cos(circleSNum1 * twoPI) * radius;
首先添加父级的坐标。这与上面的内容相矛盾,因为"对于他们的父母"已包含术语CircleL.x
。您有两种选择: