建站学习网,专业提供各类建站教程,网页素材,SEO资讯等建站资源!

网站模板_网站源码_网站素材_建站教程_建站学习网

当前位置:建站学习网 > 网页设计 > Flash教程 >

AS3文档类打造绚烂星形变幻效果

更新时间:2017-04-19整理编辑:建站学习网阅读:0

文档类:
 

package 

{

        import flash.display.Sprite;

        import flash.events.Event;

        import flash.events.MouseEvent;

        

        [SWF(backgroundColor = "0x000000", frameRate = "60")]



        public class Main extends Sprite 

        {

                private var patternList:Array = new Array();

                

                private var moveBullet:Array = new Array();

                

                public function Main():void 

                {

                        if (stage) init();

                        else addEventListener(Event.ADDED_TO_STAGE, init);

                }

                

                private function init(e:Event = null):void 

                {

                        removeEventListener(Event.ADDED_TO_STAGE, init);

                        // entry point

                        MouseDown(null);

                        

                        addEventListener(Event.ENTER_FRAME, EnterFrame );

                        stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);

                }

                

                private function EnterFrame(event:Event):void 

                {

                        var i:int = 0;

                        



                        for ( i = 0; i < patternList.length; i++ )

                        {

                                var bullet:Bullet = patternList[i].Run();

                                if ( bullet != null )

                                {

                                        addChild( bullet );

                                }

                        }

                        for ( i = patternList.length - 1; i >= 0; i-- )

                        {

                                if ( patternList[i].isEnd() )

                                {

                                        //        从待命到移动

                                        for ( var j:int = 0; j < patternList[i].waitBullet.length; j++ )

                                        {

                                                patternList[i].waitBullet[j].StartSlide();

                                                moveBullet.push( patternList[i].waitBullet[j] );                                                

                                        }

                                        patternList.splice( i, 1 );                                                

                                }

                        }

                                        

                        //        移动

                        if ( moveBullet.length > 0 )

                        {

                                for ( i = moveBullet.length - 1; i >= 0; i-- )

                                {

                                        //        

                                        if ( moveBullet[i].slideFlag )

                                        {

                                                moveBullet[i]._xx += Math.cos( moveBullet[i].slideAngle * Math.PI / 180 ) * moveBullet[i].slideSpeed;

                                                moveBullet[i]._xy += Math.sin( moveBullet[i].slideAngle * Math.PI / 180 ) * moveBullet[i].slideSpeed;

                                                moveBullet[i].x = moveBullet[i]._xx;

                                                moveBullet[i].y = moveBullet[i]._xy;

                                        

                                                if ( moveBullet[i].slideSpeed > 0 )

                                                {

                                                        moveBullet[i].slideSpeed -= moveBullet[i].slideSpeedMax / 50;

                                                        if ( moveBullet[i].slideSpeed < 0 )        moveBullet[i].slideFlag = false;

                                                }

                                                

                                        }else

                                        {        

                                                moveBullet[i]._xx += Math.cos( moveBullet[i].moveAngle * Math.PI / 180 ) * 1;

                                                moveBullet[i]._xy += Math.sin( moveBullet[i].moveAngle * Math.PI / 180 ) * 1;

                                                moveBullet[i].x = moveBullet[i]._xx;

                                                moveBullet[i].y = moveBullet[i]._xy;

                                                

                                                if ( moveBullet[i].x < -50 || moveBullet[i].x > stage.stageWidth + 50 || moveBullet[i].y < -50 || moveBullet[i].y > stage.stageHeight + 50 )

                                                {

                                                        removeChild( moveBullet[i] );

                                                        moveBullet.splice( i, 1 );

                                                }

                                        }

                                }

                        }

                }

                

                private function MouseDown(event:MouseEvent):void

                {

                        //        小星

                        patternList.push( new Pattern(stage.stageWidth / 2, stage.stageHeight / 2, false, 50, 0xFF5555, (270 + 72 * 0), 3 ) );

                        patternList.push( new Pattern(stage.stageWidth / 2, stage.stageHeight / 2, false, 50, 0xFF5555, (270 + 72 * 1), 3 ) );

                        patternList.push( new Pattern(stage.stageWidth / 2, stage.stageHeight / 2, false, 50, 0xFF5555, (270 + 72 * 2), 3 ) );

                        patternList.push( new Pattern(stage.stageWidth / 2, stage.stageHeight / 2, false, 50, 0xFF5555, (270 + 72 * 3), 3 ) );

                        patternList.push( new Pattern(stage.stageWidth / 2, stage.stageHeight / 2, false, 50, 0xFF5555, (270 + 72 * 4), 3 ) );

                        //        大星

                        patternList.push( new Pattern(stage.stageWidth/2, stage.stageHeight/2, false, 100, 0x5555FF, (270 + 72 * 0), 5 ) );

                        patternList.push( new Pattern(stage.stageWidth/2, stage.stageHeight/2, false, 100, 0x5555FF, (270 + 72 * 1), 5 ) );

                        patternList.push( new Pattern(stage.stageWidth/2, stage.stageHeight/2, false, 100, 0x5555FF, (270 + 72 * 2), 5 ) );

                        patternList.push( new Pattern(stage.stageWidth/2, stage.stageHeight/2, false, 100, 0x5555FF, (270 + 72 * 3), 5 ) );

                        patternList.push( new Pattern(stage.stageWidth/2, stage.stageHeight/2, false, 100, 0x5555FF, (270 + 72 * 4), 5 ) );

                }

                

        }

        

}

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

import flash.display.Sprite;

import flash.geom.Point;



//-----------------------------

//        图案类

class Pattern {

        

        private var reverse:Boolean = false;                

        private var starSize:Number = 150;                        

        private var bulletColor:uint = 0x000000;        

        

        private var slideAngle:Number = 0;                         

        private var slideSpeed:Number = 0;                        

        

        private var end:Boolean = false;

        private var count:int = 0;

        private var defX:int = 0;

        private var defY:int = 0;

                        

        private var target:Array = new Array();

        

        private static const PATH_OBJ_NUM:int = 20;                //        子弹数

        private static const TARGET_NUM:int = 5;

        private static const TARGET_ANGLE:Array = [ 270 + 72 * 3, 270 + 72 * 1, 270 + 72 * 4, 270 + 72 * 2, 270 ];        //        通过的目标地点的角度

        private static const TARGET_ANGLE2:Array = [ 270 + 72 * 2, 270 + 72 * 4, 270 + 72 * 1, 270 + 72 * 3, 270 ];        //        



        public        var waitBullet:Array = new Array();                

        

        public function Pattern(

                _gx:int = 0, _gy:int = 0,

                _rev:Boolean = false,

                _starSize:Number = 80,

                _bulletColor:uint = 0x000000,

                _slideAngle:Number = 0,

                _slideSpeed:Number = 0 

        ) {

                count = 0;

                defX = _gx;

                defY = _gy;

                

                reverse = _rev;

                starSize = _starSize;

                bulletColor = _bulletColor;

                slideAngle = _slideAngle;

                slideSpeed = _slideSpeed;

                

                for ( var i:int = 0; i < 5; i++ )

                {

                        var angle:Number = TARGET_ANGLE[i];

                        if ( reverse ) angle = TARGET_ANGLE2[i] + 180;        //        反転

                        else                    angle = TARGET_ANGLE[i];



                        target[i] = new Point( Math.cos( angle * Math.PI / 180 ) * starSize, Math.sin( angle * Math.PI / 180 ) * starSize );

                }

        }

        //子弹生成

        public function Run() : Bullet {

                

                var bullet:Bullet = new Bullet(bulletColor,slideAngle,slideSpeed);

                        

                var targetNo:int = int(count / PATH_OBJ_NUM);

                var targetRate:int = int(count % PATH_OBJ_NUM);

                var p:Point;



                //子弹的座标

                p = Point.interpolate( target[targetNo], target[(targetNo+(TARGET_NUM-1))%TARGET_NUM], targetRate / PATH_OBJ_NUM );                

                bullet.x = p.x + defX;

                bullet.y = p.y + defY;

        bullet._xx = p.x + defX;

        bullet._xy = p.y + defY;



                //子弹的移动角度

        //if( !reverse )        bullet.moveAngle = -count / PATH_OBJ_NUM / TARGET_NUM * 720 + 135;

                //else                        bullet.moveAngle = count / PATH_OBJ_NUM / TARGET_NUM * 720 - 135;



                bullet.moveAngle = ( -int(count / PATH_OBJ_NUM) / TARGET_NUM * 720 + 108) + ((count % PATH_OBJ_NUM) * 180 / PATH_OBJ_NUM);        //        Target始点角度 + 180 * rate        グレイソーに入る前の奴



                

                waitBullet.push( bullet );

                

                count++;

                if ( count == TARGET_NUM * PATH_OBJ_NUM )        end = true;

                

                return        bullet;

        }



        public        function isEnd() : Boolean {        return        end;        }

}



//-----------------------------

//        子弹类

class Bullet extends Sprite {

        

        public        var slideFlag:Boolean = false;        

        

        public        var slideAngle:Number = 0;

        public        var slideSpeed:Number = 0;

        public        var slideSpeedMax:Number = 0;

        public        var moveAngle:Number = 0;

        

        public        var _xx:Number = 0;

        public        var _xy:Number = 0;

        

        public function Bullet(color:uint,_slideAngle:Number = 0,_slideSpeed:Number = 50) {

                super();

                

                graphics.beginFill(color);

                graphics.drawCircle(0, 0, 5);

                graphics.endFill();

                

                graphics.beginFill(0xFFFFFF, 0.5);

                graphics.drawCircle(0, 0, 3);

                graphics.endFill();

                

                slideAngle = _slideAngle;

                slideSpeed = _slideSpeed;

                slideSpeedMax = _slideSpeed;

                

                slideFlag = false;

        }

        

        public        function StartSlide():void 

        {

                slideFlag = true;

        }

        

}

 

本文网址:https://www.dedexuexi.com/wysj/flash/3040.html

本站部分文章搜集与网络,如有侵权请联系本站,转载请说明出处。

收藏此文 赞一下!() 打赏本站

如本文对您有帮助,就请建站学习网抽根烟吧!

支付宝打赏
微信打赏
Flash教你制作水滴掉落动画效果
« 上一篇2017年04月19日
Flash播放 嵌入音频文件的方法
2017年04月19日下一篇 »
  • 使用Flash MX将GIF动画图片制成FLASH动画
    0阅读
    gif动画比较简单 gif动画只能做一些比较简单的动画,FLASH可以比较多元化,最大的不同是格式不一样,一个是SWF,一个是Gif,还有Gif的那是图片,按照flash里面讲Gif是逐贞动画 PS也可以做,而
  • flash动画制作网页中演示类FLASH动画的制作规范
    0阅读
    在工作中所遇到的涉及到flash的项目一般会根据其具体应用分成两大类:演示类 交互类为了使项目更加快速有效的完成并且保证工作质量,使源文件从结构上更加的简洁易读,有必要遵守一定的
  • flash as3实现打字小游戏代码
    0阅读
    游戏效果 新建Fla,在第一帧F9添加代码即可。 代码如下 var arr:Array = new Array(); var time:uint=0; var angle:Number=0; var zfun; [SWF(width=800, height=465,backgroundColor=0...
  • Flash制作旋转的花朵
    0阅读
    思路: 1.使用for...in语句遍历整个主场景(_root)中所有的对象; 2.找到他们(如_root[k]),并为他们的不同方法指定不同函数; 步骤1: 在主场景放入若干个影片剪辑,不需要为他们起实例名。 步骤2:加入
  • Flash片头加载loading的方法
    0阅读
    做一个优秀的loading是衡量一个flasher水准、甚至态度的,因为loading是唯一一个你不会多看而所有用户、客户会看的东西,所以你对loading的重视程度,甚至可以反衬你这个flasher的职业道德。 我认
 
QQ在线咨询
×
欢迎您登陆建站学习网
QQ一键登陆 建站学习网账号登录