package com.upupgame.utils
{
    import com.greensock.*;
    import com.greensock.easing.Quint;
    import com.upupgame.baccarat.audio.SoundBiz;
    import com.upupgame.baccarat.player2.assets.MainAssets;
                                                                                                                                                       
    import flash.display.MovieClip;
    import flash.geom.Matrix;
    import flash.geom.Point;
                                                                                                                                                       
    import hs.framework.utils.delay;
                                                                                                                                                       
    /**
     * ...
     * @author
     */
    public class CoinsEmitter
    {
//      private static var X:Number;
//      private static var Y:Number;
        private static var startLocation : Point;
        private static var nodeLocation : Point;
        private static var endLocation : Point;
        private static var num : Number;
        private static var count : uint = 0;
                                                                                                                                                           
        public function CoinsEmitter()
        {
                                                                                                                                                           
        }
                                                                                                                                                           
//      public static function StartShoot(num:Number,start : Point,node:Point,end:Point = null):void{
        /**
         * @param num:Number 元件的个数
         * @param start : Point 开始飞的位置
         * @param end:Point = null 结束的位置(默认为<50,20>)
         * @param postion 用来计算贝塞尔曲线 0 : 偏上 , 1 : 偏下 , 2 : 偏左 , 3 : 偏右
         * */
        public static function StartShoot(num:Number,start : Point,end:Point = null,postion : uint = 2):void{
            count = 0;
            CoinsEmitter.startLocation = start;
//          CoinsEmitter.nodeLocation = node;
            if(end != null ){
                CoinsEmitter.endLocation = end;
            }else{
                CoinsEmitter.endLocation = new Point(50,20);
            }
            var $node : Point = new Point();
            var $maxX : int = 0;
            var $maxY : int = 0;
            var $minX : int = 0;
            var $minY : int = 0;
            if(start.x < CoinsEmitter.endLocation.x ){
                $maxX = CoinsEmitter.endLocation.x;
                $minX = start.x;
            }else{
                $minX = CoinsEmitter.endLocation.x;
                $maxX = start.x;
            }
            if(start.y < CoinsEmitter.endLocation.y){
                $maxY = CoinsEmitter.endLocation.y;
                $minY = start.y;
            }else{
                $minY = CoinsEmitter.endLocation.y;
                $maxY = start.y;
            }
            switch(postion){
                case 0:
                    $node.x = $maxX;
                    $node.y = $maxY - ($maxX - $minX)/4;
                    break;
                case 1:
                    $node.x = $minX;
                    $node.y = ($maxX - $minX)/4 + $minY;
                    break;
                case 2:
                    $node.x = $minX;
//                  $node.y = (5*$maxY + $minY)/4;
                    $node.y = (15*$maxY + 16*$minY)/16;
                    break;
                case 3:
                    $node.x = $maxX;
//                  $node.y = (3*$minY - $maxY)/4;
                    $node.y = ($maxY + 15*$minY)/16;
                    break;
                default:
                    $node.x = $minX;
                    $node.y = (15*$maxY + 16*$minY)/16;
                    break;
            }
            CoinsEmitter.nodeLocation = $node;
            CoinsEmitter.num = num;
//          var len:int = num / 500;
            if (num < 20){
                num = 20;
            }else if (num > 50){
                num = 50;
            }
            GameMain.soundManager.play(SoundBiz.FLY_CHIP);
            for (var i:int = 0; i < num; i+=1){
                delay((_getRandom(0, 1) * 1000), delayShoot);
            }
            function delayShoot():void
            {
                var mDot:MovieClip;
                if(_getRandom(0,num) <= num/7){
                    mDot = getFlash();
                }else{
                    mDot = _getNewDot();
                }
                GameMain.instance.layers.chat.addChild(mDot);
                _tweenDot(mDot, 0);
            }
        }
                                                                                                                                                           
        private static function _tweenDot(dot:MovieClip, dt:Number):void{
            var $note : Point = new Point();
            $note.x = CoinsEmitter.nodeLocation.x + _getRandom(-CoinsEmitter.num*2.5,CoinsEmitter.num*2.5);
            $note.y = CoinsEmitter.nodeLocation.y + _getRandom(-CoinsEmitter.num*2.5,CoinsEmitter.num*2.5);
            TweenLite.to(dot, 2, {bezier:[{x:$note.x, y:$note.y}, {x:CoinsEmitter.endLocation.x, y:CoinsEmitter.endLocation.y}], scaleX : dot.scaleX*0.8,
                scaleY : dot.scaleY*0.8
                ,orientToBezier:true,
                ease:Quint.easeInOut,delay: dt,onComplete: firstTweenComplete, onCompleteParams: [dot]});
            function firstTweenComplete(dot:MovieClip):void{
                if (dot)
                {
                    if (dot.parent)
                    {
                        dot.parent.removeChild(dot);
                    }
                    dot = null;
                }
                if( ++ count >= num){
                    if(startLocation != null)startLocation = null;
                    if(nodeLocation != null)nodeLocation = null;
                    if(endLocation != null )endLocation = null;
                    count = 0;
                }
            }
        }
                                                                                                                                                           
        private static function _getNewDot():MovieClip{
            var num:int = int(_getRandom(1,4));
            var mCoin:MovieClip = new (com.upupgame.baccarat.player2.assets.MainAssets["Coins" + num])() as MovieClip;
            var $scale : Number = _getRandom(0.2,0.5);
            var $myMatrix : Matrix = new Matrix($scale,_getRandom(-Math.PI/9,Math.PI/9),_getRandom(-Math.PI/10,Math.PI/10),$scale,
                CoinsEmitter.startLocation.x + _getRandom(-50,50)
                ,CoinsEmitter.startLocation.y + _getRandom(-50,50)
            );
            mCoin.transform.matrix = $myMatrix;
            mCoin.alpha = _getRandom(5,10)/10;
            mCoin.gotoAndPlay(_getRandom(3,9));
            return mCoin;
        }
        private static function getFlash() : MovieClip{
            var $myFlash : MovieClip = new (com.upupgame.baccarat.player2.assets.MainAssets["CoinFlash"]) as MovieClip;
            var $scale : Number = _getRandom(0.3,0.6);
            var $myMatrix : Matrix = new Matrix($scale,_getRandom(-Math.PI/8,Math.PI/8),_getRandom(-Math.PI/8,Math.PI/8),$scale,
                CoinsEmitter.startLocation.x + _getRandom(-50,50)
                ,CoinsEmitter.startLocation.y + _getRandom(-50,50)
            );
            $myFlash.transform.matrix = $myMatrix;
            $myFlash.alpha = _getRandom(5,10)/10;
            $myFlash.gotoAndPlay(_getRandom(1,50));
            return $myFlash;
        }
                                                                                                                                                           
        private static function _getRandom(min:Number, max:Number):Number{
            return min + (Math.random() * (max - min));
        }
                                                                                                                                                       
    }
}

做一个解释:

①:此瓢金币的效果使用的是贝塞尔曲线.

    ②:为了得到贝塞尔曲线的效果,至少需要3个点(你懂得),中间的曲线点是由此类(上)来自动计算的.并且,每个中间点都做了一个随机的偏移.

    ③:此类(上)对金币由"_getNewDot()"获得,对星星由"getFlash()"获得,都做了矩阵的变形,类外其透明度也做了一个渐变的处理(越来越透明)

    ④:对于瓢金币(包括星星)的起始位置也做了偏移

    ⑤:加了一个瓢金币的音乐,当然读者要测试的话,还需知己写一个音乐管理器.当然,也可以去掉音乐.

    ⑥:效果很不错哦.j_0020.gif