【发布时间】:2011-03-15 17:04:46
【问题描述】:
我正在使用 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);
【问题讨论】:
标签: flash actionscript-3 rotation drag gsap