Flash AS3代码打造绚烂的星形变幻效果

  发布时间:2014-11-05 15:42:02   作者:佚名   我要评论
本教程是向程序员之家的朋友介绍利用Flash AS3代码打造绚烂的星形变幻效果方法,教程制作出来的星形还是很漂亮的,推荐过来,一起来学习吧
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

这篇教程主要向大家讲解如何利用Flash AS3代码打造绚烂的星形变幻效果,教程并没有对每一个代码做出讲解,但也不是很难,分享到程序员之家,喜欢的朋友一起来学习吧! 


复制代码
代码如下:
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;
 }
 }

以上就是Flash AS3代码打造绚烂的星形变幻效果的方法介绍,希望能帮到大家,谢谢阅读!

相关文章

  • flash cs6鼠标跟随效果实现代码分享

    flash cs6想要实现鼠标跟随效果?该怎么制作呢?今天我们就来看看使用as2.0实现鼠标跟随效果的教程,需要的朋友可以参考下
    2019-05-19
  • Flash cs6怎么使用代码输入中英文文本?

    Flash cs6怎么使用代码输入中英文文本?Flash cs6中可以使用文字工具直接输入文本,也可以使用代码来输入文本,该怎么使用代码输入文本呢?请看下文详细的教程,需要的朋友
    2018-03-11
  • flash as3.0怎么定义抽象类和抽象?

    flash as3.0抽象类怎么定义? as3.0中有很多抽象类,该怎么定义抽象类和抽象方法呢?下面我们就来看看简单的例子,需要的朋友可以参考下http://www.jb51.net/softs/408402.
    2018-02-28
  • flash cs6中怎么使用ActionScript3.0?

    flash cs6中怎么使用ActionScript3.0?flash cs6中想要使用ActionScript3.0功能,该怎么使用呢?下面我们就来看看详细的教程,需要的朋友可以参考下
    2018-01-25
  • Flash中怎么实现鼠标点击决定图像位置?

    本教程给大家分享一个Flash小教程,教大家在Flash CS6中怎么实现鼠标点击决定图像位置?方法很简单,感兴趣的朋友欢迎前来一起分享学习
    2018-01-12
  • Flash中如何用代码将图片放在自己想要的舞台位置?

    本教程教程序员之家的ActionScript教程学习者在Flash中如何用代码将图片放在自己想要的舞台位置,教程讲解的详细,感兴趣的朋友欢迎前来分享学习
    2017-11-20
  • 在Flash CS6中使用with函数绘制背景图教程

    本教程教程序员之家的ActionScript教程学习者如何在Flash CS6中使用with函数绘制背景图?教程一步步讲解的挺详细,方法也不难,非常适合Flash新手入门学习
    2017-11-18
  • Flash怎么设置元件坐标?flash使用代码设置元件的坐标的教程

    Flash怎么设置元件坐标?flash中导如的元件需要添加坐标,该怎么定位元件坐标呢?下面我们就来看看flash使用代码设置元件的坐标的教程,需要的朋友可以参考下
    2017-10-11
  • Flash怎么制作来回摇摆的花朵的动画?

    Flash怎么制作来回摇摆的花朵的动画?Flash中想要给花朵制作一段摇摆的动画效果,该怎么制作呢?下面我们就来看看详细的教程,很简单,需要的朋友可以参考下
    2017-05-23
  • Flash怎么制作流动七彩色的文字?

    Flash怎么制作流动七彩色的文字?想要让文字动起来,该怎么使用flash给文字制作一个流动七彩色的动画呢?下面我们就来看看详细的教程,需要的朋友可以参考下
    2017-04-23

最新评论

?


http://www.vxiaotou.com