简体   繁体   中英

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);
            }
        }

Regular.easeOut is supposed to perform the above behavior.

Sometimes, while having multiple tweens with easing, flash even misses out the final point.

So if you do have to use easeout, add a tween complete event wherein you set the final point manually.

Else use None.easeNone

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM