Spinning Wheel in flash AS3

雨燕双飞 提交于 2019-12-23 02:43:13

问题


I want to create (roulette) spinning wheel simulation in FLASH.

I want to get a number, where that (roulette) spinning wheel will stop in front of an indicator.

Here is link which demonstrate what I want actually. http://zytwebdev.zoomyourtraffic.in/amol_zytwebdev/roullete/R1_wheel2.swf

section = new Array();

section[0] = "1";
section[1] = "2";
section[2] = "3";
section[3] = "4";
section[4] = "5";
section[5] = "6";
section[6] = "7";
section[7] = "8";
section[8] = "9";
section[9] = "10";
section[10]= "11";
section[11]= "12";
section[12]= "13";
section[13]= "14";
section[14]= "15";
rotate = 0;

//button press
button.onPress = function()
{
    spinWheel();
}

//create a function to speed the wheel, slow it down, stop then display result
function spinWheel()
{
    speed = 10; //the speed the wheel rotates
    count = 0;
    button.enabled = false; //while the wheel is spinning disable the button
    limit = random(40)+10; //random time for the wheel to spin before slowing down
    onEnterFrame = function()
    {
        rotate += speed;
        degrees = rotate; // DEBUG print the rotation

        //trace(degrees+" Deg");
        if (rotate>359)
        {
            rotate = rotate - 360;
        }
        //slow the wheel down
        if (count>limit)
        {
            if (speed>0)
            {
                speed -= 1.3
            } 
            else
            {
                //stop the wheel
                speed = 0;
                onEnterFrame = false;
                button.enabled = true; //enable the button

                prize = section[Math.floor(rotate/24)] ; //display the result
                printsection = Math.floor(rotate/24); // DEBUG print the section number
                trace(prize);
            }
        }
        //move wheel if speed is greater than 0
        if (speed>0){
            wheelHolder.wheel._rotation = rotate;
            count++;
        }
    }
}

And Here is working code for same.

Any help will be important for me. Thanks in advance.


回答1:


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

}



回答2:


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!



来源:https://stackoverflow.com/questions/21695106/spinning-wheel-in-flash-as3

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