简体   繁体   English

闪光飞轮AS3

[英]Spinning Wheel in flash AS3

I want to create (roulette) spinning wheel simulation in FLASH. 我想在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 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. 提前致谢。

I mad this simple wheel 4ya. 我为这个简单的轮子4ya疯狂。 http://b3vad.persiangig.com/Drop/Untitled-1.swf 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. 将360度划分为多种可能性。 Try to keep it a round value but it isn't a requirement. 尝试将其保留为整数值,但这不是必需的。

Using TweenLite or TweenMax, make the rotation. 使用TweenLite或TweenMax进行旋转。 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. 当滚轮停止并触发onComplete事件时,请查看旋转在阵列中的位置。

Like if you divide 360 in 36 options, you would get 10 degrees between each element. 就像将360分成36个选项一样,每个元素之间的角度为10度。 So 54 rotation would mean its at the 5th element (round down). 因此54旋转意味着它位于第5个元素(向下舍入)。 249 rotation would mean the 24'th element. 旋转249即表示第24个元素。

You just do 你只是做

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

to get the index of myArrayOfOptions. 获取myArrayOfOptions的索引。

You can take it from there. 您可以从那里拿走。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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