【问题标题】:Flash AS3 - Click, drag and spin - check direction of spinFlash AS3 - 单击、拖动和旋转 - 检查旋转方向
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 谢谢,我正在使用弧度 = Math.atan2(vinyl_mc.mouseY,vinyl_mc.mouseX); endAngle = ((弧度 * (180 / Math.PI)) + 450)%360;这让我到了那里。将查看上面的内容并检查一下。
    • 谢谢,那行得通。我实际上最终使用了 tweenlite 的 onUpdate 功能来编写一个临时旋转值并检查它是否与 mousemove 旋转相匹配,但交叉产品也可以工作。
    猜你喜欢
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多