0

在我的 Flash 文件中,我有一个轮子。用户可以通过使用箭头来旋转轮子以跳转到下一个“段”(想想 20 个相互连接的图像形成轮子的圆周)。 车轮

单击箭头将启动此代码:

protected function rotate():void
        {
            var rotateTo:Number = (-360 / numItems) * currentItem + 90;
            TweenLite.to(planesHolder, 1, { rotationY:rotateTo, ease:Quint.easeInOut } );
        }

但是,我想要做的是,单击并拖动以旋转轮子,完成加速和减速,甚至在轮子减速到一定速度时稳定在最近的图像上。我不知道该怎么做:我需要检测光标的前后位置,并将其转换为轮子的速度,然后随着时间的推移减速,并检测哪个图像在某个位置最近速度并“捕捉”它,上下滚动。(它只会影响 Y 轴)

任何帮助,将不胜感激

4

1 回答 1

1

鼠标按下时,在 Enter_frame 中检查当前位置到前一个位置的偏移量:

private function enterFrameHandler(e:Event)
{
  offset = oldy - oldMousePosition;
  oldy = oldMousePosition
}

这应该给你当前的速度。(显然,对于轮子,它又是 enterFrame 中的“wheel.rotation += offset / some_value_to_slow_it_down”)。

要引入“缓动”,您可以使用摩擦变量。

再次,在 enterFrame 事件中:

offset *= .8;

然后为了捕捉到下一张图像,请检查您当前的速度有多快;如果它低于某个容差,则将速度设置为 0 并将其缓和到最接近的值。(你猜对了,再次在 enterFrame 事件中

if(offset < 1)
{
  offset = 0;
  //calculate the nearest value of the wheel
  //tweenlite right over there
}
于 2010-10-28T11:53:03.187 回答