1

如何使用 TweenLite [actionscript 3 library] 使对象以圆周运动从 (startX,startY) 移动到 (destinationX,destinationY) 并有一些像差?

4

1 回答 1

1

您应该能够使用CirclePath2D插件设置圆周运动,并且可以使用函数稍微偏移位置onUpdate。听起来令人困惑的一点是

从 (startX,startY) 到 (destinationX, destinationY)

因为如果你做圆周运动,在某个点你会从你开始的地方结束。如果您从一个位置开始并在另一个位置结束,您可能会沿着曲线移动,在这种情况下,您需要查看BezierThroughPlugin

尽管如此,使用 onEnterFrame 循环在圆形路径上制作动画还是相当简单的,例如,您可以轻松地将圆形更改为椭圆形或随机稍微偏移路径。通常你需要从极坐标转换为笛卡尔坐标:

 x = cos(angle) * radius
 y = sin(angle) * radius

但是 Point 的polar()方法已经为您做到了:

var speed:Number = 0;//how fast to move around the circle
var spread:Number = 20;//how far away from the centre

var b:Sprite = addChild(new Sprite()) as Sprite;
b.graphics.beginFill(0);
b.graphics.drawCircle(-3,-3,3);
b.graphics.endFill();
graphics.lineStyle(1,0xDEDEDE);



this.addEventListener(Event.ENTER_FRAME,update);
function update(event:Event):void{
    speed += .1;//update the 'angle' , .1 is the increment/speed at which b spins
    var distance:Number = spread + (Math.random() * 10 - 5);//spread + random 'aberration'
    var offset:Point = Point.polar(distance,speed);//convert from angle/radius to x,y

    b.x = mouseX + offset.x;
    b.y = mouseX + offset.y;

    graphics.lineTo(b.x,b.y);
}
于 2012-04-13T23:24:42.737 回答