2012-08-07 51 views
0

我想弄清楚在AS3中如何使2個對象相互循環。例如,可以說2個物體是杯子。我希望他們繞着一圈轉圈。另一種看待它的方式是,它們每個都在同一個圓圈中移動,但彼此相對,這樣看起來它們正在旋轉。我需要圓的直徑是一個變量。在AS3中進行補間以使對象相互循環

我已經嘗試了一些東西,但似乎無法得到它的權利。

+0

你的意思是圍繞一個共同的點都旋轉?我不確定兩個物體如何相互循環。 – BadFeelingAboutThis 2012-08-07 22:35:04

+0

你有沒有想過這個? – BadFeelingAboutThis 2012-08-29 18:40:53

回答

1

下面是一個將圈出另一個精靈的類的簡單例子。

public class C extends Sprite { 
    public var target:Sprite; 
    private var curTan:Number = 0; 

    public var distance:Number = 200; 
    public var speed:Number = .05; 
    public var decay:Number = .05; 

    public function C(size:Number = 10, color:uint = 0xFF0000, seed:Number = 0) { 
     curTan = seed; 

     graphics.beginFill(color); 
     graphics.drawCircle(0, 0, size); 
    } 

    public function go(target_:Sprite):void { 
     target = target_; 
     addEventListener(Event.ENTER_FRAME, tick, false, 0, true); 
    } 

    protected function tick(e:Event):void { 
     x += ((target.x + Math.sin(curTan) * distance) - x) * decay; 
     y += ((target.y + Math.cos(curTan) * distance) - y) * decay; 

      //if you don't want a decay (only useful if the target is moving) then use this instead: 
      //x = target.x + Math.sin(curTan) * distance; 
      //y = target.y + Math.cos(curTan) * distance; 
     curTan += speed; 
    } 
} 
相關問題