Zec*_*row 3 actionscript actionscript-3
var circles:Array = new Array();
for(var i:int = 0; i < 8; i++)
{
var ball:Ball = new Ball();
ball.x = ???
ball.y = ???
circles.push(ball);
}
Run Code Online (Sandbox Code Playgroud)
将球定位在某个点附近的最佳方法是什么,比如相距5-10的距离,是否有一些公式?
for(var i:int = 0; i < 8; i++)
{
var ball:Ball = new Ball();
// Point has a useful static function for this, it takes two parameters
// First, length, in other words how far from the center we want to be
// Second, it wants the angle in radians, a complete circle is 2 * Math.PI
// So, we're multiplying that with (i / 8) to place them equally far apart
var pos:Point = Point.polar(50, (i / 8) * Math.PI * 2);
// Finally, set the position of the ball
ball.x = pos.x;
ball.y = pos.y;
circles.push(ball);
}
Run Code Online (Sandbox Code Playgroud)