Search code examples
actionscript-3flashairtween

Set rotation flash tween to shortest distance as3?


I am working on an adobe air interactive table project and I'm trying to tween some rotations. For the most part it works fine, but occasionally it spins aaall the way around version just spinning a little to the other direction. Does anyone of a good way to prevent this in the flash tweens?

A snippet of my code:

var rotatePos:Number;
        if (event.rotation > 180) { rotatePos = event.rotation - 360; } else { rotatePos = event.rotation; }
        var rotateDifference:Number = Math.abs(Math.abs(rotatePos) - Math.abs(Number(rotationCurrent[tempCircleNumber])));
        if ( rotateDifference > 4 && rotateDifference < 60) {
            rotateTheFiducial();
        } else if ( rotateDifference > 100 ) {
            trace("too far, ignore : " + rotateDifference);
        }
        function rotateTheFiducial():void
        {
            try
            {
                var cardTweenRotation:Tween = new Tween(MovieClip(fiducialArray[tempCircleNumber]), "rotation", Regular.easeOut, Number(rotationCurrent[tempCircleNumber]), rotatePos, .2, true);

                rotationCurrent[tempCircleNumber] = rotatePos;

            }
            catch (e:Error)
            {
                trace(fiducialId + " : Rotate Error : " + e);
            }
        }

Solution

  • You really should avoid using Flash built-in Tween engine. Its slow, bloated, and is lacking a lot of really useful things.

    Try using TweenLite/TweenMax or better, eaze that both have built-in functions for short rotations like you are facing. They are waaaay faster than using the default Tween engine ! (as you can see here)

    Not only you will be able to sort that kind of short-rotation problems, but your app will gets faster with one of them :-)