AS3 :转盘实现

2019-06-14  本文已影响0人  一眼就认出你

代码如下:

        //转动的位置
        private var _index: Number;

        //初始化游戏
        private function init():void{
            _index=0;
        }

        //点击事件触发转动
         private function clickHandler(event:Event): void {
             _index=++_index%8;
             console.log(" 下标 "+_index);
             startRotate();
         }

         /**开始转动奖励盘 */
        private function startRotate(): void {
            _luckRollerViewUI.arrowBox.rotation = 0;
            var destination: Number = 1440 + (9-_index) * 45 ;
            var a: Tween = Tween.to(_luckRollerViewUI.arrowBox, { "rotation": destination }, 4000, Ease.quadOut, Handler.create(this, function ():void {
                  Tween.clear(a);
            }));
        }

解释:
arrowBox:转动装盘的图片变量
rotation:转动的角度
1440 + (9-_index) * 45 :用于装盘转动
1440 + _index * 45 :用于指针转动
(注意:1440是360的2倍->转两圈 45*8=360,代表8个分片,若是6个分片,改为60即可 )
Tween.to:缓动
Ease.quadOut:缓动函数类型

上一篇 下一篇

猜你喜欢

热点阅读