2
我正在使用綠色的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);
謝謝,我使用弧度= 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