Flash AS3 - 单击,拖动和旋转 - 检查旋转的方向
问题描述:
我正在使用绿色的tweenlite单击,拖动和旋转圆形的动画片段,并具有以下内容。Flash AS3 - 单击,拖动和旋转 - 检查旋转的方向
我需要做的是确定旋转的方向和速度,即如果用户正在将车轮旋转到右侧,则将该方向存储在字符串变量中,并将旋转速度存储在数字变量中。
我已经尝试了许多不同的事情与mousestart和移动坐标,并与乙烯基_mc旋转坐标,但不能得到任何可靠的东西。有没有一种方法可以确定方向和速度并将它们存储在变量中?
该应用程序可以在:http://s46264.gridserver.com/dev/dave/rotate/rotate.html 和源FL是: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);
答
怎么样在圆的边缘创建一个标记物体,做一些三角形来获得角度,再次检查一下比较两者。角度随着时间的推移会给你速度,angle1-angle2会给你方向。
谢谢,我使用弧度= Math.atan2(vinyl_mc.mouseY,vinyl_mc.mouseX); ((radians *(180/Math.PI))+ 450)%360;这是让我参与的一部分。将看看上面的内容并检查出来。 – digitalpencil 2011-03-16 00:28:22
谢谢,那工作。实际上,我最终使用tweenlite的onUpdate功能编写了一个临时旋转值,并检查了鼠标移动的旋转,但是跨产品也是如此。 – digitalpencil 2011-03-17 14:39:17