在AS3中进行补间以使对象相互圈起来

时间:2012-08-07 21:57:00

标签: actionscript-3 tween flash-cs6

我正在试图弄清楚AS3如何让2个物体相互圈起来。例如,假设2个对象是杯子。我希望他们围成一圈旋转。另一种看待它的方式是,它们每个都在同一个圆圈中相互交叉,所以看起来它们正在旋转。我需要圆的直径作为变量。

我尝试过很多东西,但似乎无法做到。

1 个答案:

答案 0 :(得分: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;
    }
}