【问题标题】:Spinning Wheel in flash AS3Flash AS3 中的纺车
【发布时间】:2014-03-08 20:10:48
【问题描述】:

我想在 FLASH 中创建(轮盘赌)纺车模拟。

我想得到一个数字,那个(轮盘赌)旋转的轮子会停在一个指示器前面。

这里是展示我实际想要什么的链接。 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++;
        }
    }
}

这是相同的工作代码。

任何帮助对我来说都很重要。 提前致谢。

【问题讨论】:

  • 分享代码 sn-p,而不仅仅是输出。
  • 您可以使用 Math.random 获取它应该站立的数字并在开始旋转之前设置旋转。其余的很容易。一个循环动画,在它开始的地方停止。

标签: actionscript-3 flash spinning


【解决方案1】:

我为这个简单的轮子 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】:

    在一系列可能性中划分 360 度。尽量保持整数值,但这不是必需的。

    使用 TweenLite 或 TweenMax 进行旋转。我相信你想要的有一个 sn-p。否则,请使用缓动设置。

    当轮子停止并触发 onComplete 事件时,查看您的旋转在阵列中的哪个位置。

    就像如果你将 360 分为 36 个选项,你会得到每个元素之间的 10 度。所以 54 次旋转意味着它在第 5 个元素(向下舍入)。 249 次旋转意味着第 24 个元素。

    你只是这样做

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

    获取 myArrayOfOptions 的索引。

    你可以从那里拿走它。

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2012-09-19
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多