2012-08-07 49 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; 
    } 
}