2

我正在使用 greensock tweenlite 来单击、拖动和旋转圆形影片剪辑,到目前为止有以下内容。

我需要做的是确定旋转的方向和速度,即如果用户将轮子向右旋转,则将此方向存储在一个字符串变量中,比如将旋转速度存储在一个数字变量中。

我用 mousestart 和 move 坐标以及vinyl_mc 旋转坐标尝试了许多不同的东西,但没有得到任何可靠的东西。有没有办法可以确定方向和速度并将它们存储在变量中?

该应用程序可以在:http : //s46264.gridserver.com/dev/dave/rotate/rotate.html 查看,源代码在:http://s46264.gridserver.com/dev/dave/rotate/rotate。 fla.zip如果这有帮助的话。

谢谢。

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.*;

TweenPlugin.activate([ShortRotationPlugin]);
var oldRotation,ax,ay,bx,by,thetaA,thetaB,delTheta,newTheta:Number;

var direction:String;

function dragger(evt:MouseEvent)
{
    if (evt.type == MouseEvent.MOUSE_DOWN)
    {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, dragger);
        stage.addEventListener(MouseEvent.MOUSE_UP, dragger);
        oldRotation = vinyl_mc.rotation;
        ax = stage.mouseX - vinyl_mc.x;
        ay = stage.mouseY - vinyl_mc.y;
        thetaA = Math.atan2(ay,ax) * 180 / Math.PI;
        if (thetaA < 0)
        {
            thetaA =  -  thetaA;
        }
        else
        {
            thetaA = 360 - thetaA;
        }

    }
    else if (evt.type == MouseEvent.MOUSE_MOVE)
    {

        bx = stage.mouseX - vinyl_mc.x;
        by = stage.mouseY - vinyl_mc.y;
        thetaB = Math.atan2(by,bx) * 180 / Math.PI;

        if (thetaB < 0)
        {
            thetaB =  -  thetaB;
        }
        else
        {
            thetaB = 360 - thetaB;
        }

        delTheta = thetaB - thetaA;
        newTheta = oldRotation - delTheta;

        TweenLite.to(vinyl_mc, 1, {shortRotation:{rotation:newTheta}, overwrite:true, ease:Cubic.easeOut});

    }
    else if (evt.type == MouseEvent.MOUSE_UP)
    {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragger);
        stage.removeEventListener(MouseEvent.MOUSE_UP, dragger);
    }
}


vinyl_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragger);
4

1 回答 1

0

在圆的边缘创建一个标记对象怎么样,做一些三角函数来获得角度,再次检查比较两者。随着时间的推移,角度会给你速度,角度1-角度2会给你方向。

于 2011-03-15T23:38:43.637 回答