我正在使用 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);