2012-04-13 45 views
1

如何使用TweenLite [動作腳本3庫]使對象以(startX,startY)到(destinationX,destinationY)的圓周運動產生一定的畸變?TweenLite圓周運動

+0

這是非常模糊的。你能否進一步解釋你想要達到的目標?你有什麼嘗試? – Corey 2012-04-13 15:00:24

回答

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); 
}