Spinning Wheel in flash AS3

穿精又带淫゛_ 提交于 2019-12-08 01:15:25

I mad this simple wheel 4ya. http://b3vad.persiangig.com/Drop/Untitled-1.swf

package {

import flash.display.MovieClip;
import flash.events.MouseEvent;


public class main extends MovieClip {


    public function main() {
        addEventListener(MouseEvent.CLICK,clcks);
    }

    public function clcks(e:MouseEvent):void {
        if (e.target.name == "doit") {
            var rr = Math.round(Math.random()*360);
            spn.rotation=-rr;
            spn.play();
            trace(Math.round(rr/22.5));
        }
    }
}

}

Divide 360 degrees in an array of possibilities. Try to keep it a round value but it isn't a requirement.

Using TweenLite or TweenMax, make the rotation. I am sure there is a snippet for what you want. Else, play with easing settings.

When the wheel stops and the onComplete events gets triggered, see where in you array does your rotation stand.

Like if you divide 360 in 36 options, you would get 10 degrees between each element. So 54 rotation would mean its at the 5th element (round down). 249 rotation would mean the 24'th element.

You just do

Math.floor( myWheel.rotation / ( 360 / myArrayOfOptions.length ) )

to get the index of myArrayOfOptions.

You can take it from there.

Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!