Flash AS3代碼打造絢爛的星形變幻效果
發(fā)布時(shí)間:2014-11-05 15:42:02 作者:佚名
我要評(píng)論
本教程是向腳本之家的朋友介紹利用Flash AS3代碼打造絢爛的星形變幻效果方法,教程制作出來(lái)的星形還是很漂亮的,推薦過(guò)來(lái),一起來(lái)學(xué)習(xí)吧
這篇教程主要向大家講解如何利用Flash AS3代碼打造絢爛的星形變幻效果,教程并沒(méi)有對(duì)每一個(gè)代碼做出講解,但也不是很難,分享到腳本之家,喜歡的朋友一起來(lái)學(xué)習(xí)吧!
復(fù)制代碼
代碼如下: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() )
{
// 從待命到移動(dòng)
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 );
}
}
// 移動(dòng)
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;
//-----------------------------
// 圖案類(lèi)
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; // 子彈數(shù)
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 ]; // 通過(guò)的目標(biāo)地點(diǎn)的角度
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;
//子彈的座標(biāo)
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;
//子彈的移動(dòng)角度
//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始點(diǎn)角度 + 180 * rate グレイソーに入る前の奴
waitBullet.push( bullet );
count++;
if ( count == TARGET_NUM * PATH_OBJ_NUM ) end = true;
return bullet;
}
public function isEnd() : Boolean { return end; }
}
//-----------------------------
// 子彈類(lèi)
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;
}
}
{
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() )
{
// 從待命到移動(dòng)
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 );
}
}
// 移動(dòng)
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;
//-----------------------------
// 圖案類(lèi)
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; // 子彈數(shù)
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 ]; // 通過(guò)的目標(biāo)地點(diǎn)的角度
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;
//子彈的座標(biāo)
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;
//子彈的移動(dòng)角度
//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始點(diǎn)角度 + 180 * rate グレイソーに入る前の奴
waitBullet.push( bullet );
count++;
if ( count == TARGET_NUM * PATH_OBJ_NUM ) end = true;
return bullet;
}
public function isEnd() : Boolean { return end; }
}
//-----------------------------
// 子彈類(lèi)
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代碼打造絢爛的星形變幻效果的方法介紹,希望能幫到大家,謝謝閱讀!
相關(guān)文章

flash cs6鼠標(biāo)跟隨效果實(shí)現(xiàn)代碼分享
flash cs6想要實(shí)現(xiàn)鼠標(biāo)跟隨效果?該怎么制作呢?今天我們就來(lái)看看使用as2.0實(shí)現(xiàn)鼠標(biāo)跟隨效果的教程,需要的朋友可以參考下2019-05-19
Flash cs6怎么使用代碼輸入中英文文本?Flash cs6中可以使用文字工具直接輸入文本,也可以使用代碼來(lái)輸入文本,該怎么使用代碼輸入文本呢?請(qǐng)看下文詳細(xì)的教程,需要的朋友2018-03-11
flash as3.0抽象類(lèi)怎么定義? as3.0中有很多抽象類(lèi),該怎么定義抽象類(lèi)和抽象方法呢?下面我們就來(lái)看看簡(jiǎn)單的例子,需要的朋友可以參考下http://www.fzitv.net/softs/408402.2018-02-28
flash cs6中怎么使用ActionScript3.0?
flash cs6中怎么使用ActionScript3.0?flash cs6中想要使用ActionScript3.0功能,該怎么使用呢?下面我們就來(lái)看看詳細(xì)的教程,需要的朋友可以參考下2018-01-25
Flash中怎么實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊決定圖像位置?
本教程給大家分享一個(gè)Flash小教程,教大家在Flash CS6中怎么實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊決定圖像位置?方法很簡(jiǎn)單,感興趣的朋友歡迎前來(lái)一起分享學(xué)習(xí)2018-01-12
Flash中如何用代碼將圖片放在自己想要的舞臺(tái)位置?
本教程教腳本之家的ActionScript教程學(xué)習(xí)者在Flash中如何用代碼將圖片放在自己想要的舞臺(tái)位置,教程講解的詳細(xì),感興趣的朋友歡迎前來(lái)分享學(xué)習(xí)2017-11-20
在Flash CS6中使用with函數(shù)繪制背景圖教程
本教程教腳本之家的ActionScript教程學(xué)習(xí)者如何在Flash CS6中使用with函數(shù)繪制背景圖?教程一步步講解的挺詳細(xì),方法也不難,非常適合Flash新手入門(mén)學(xué)習(xí)2017-11-18
Flash怎么設(shè)置元件坐標(biāo)?flash使用代碼設(shè)置元件的坐標(biāo)的教程
Flash怎么設(shè)置元件坐標(biāo)?flash中導(dǎo)如的元件需要添加坐標(biāo),該怎么定位元件坐標(biāo)呢?下面我們就來(lái)看看flash使用代碼設(shè)置元件的坐標(biāo)的教程,需要的朋友可以參考下2017-10-11
Flash怎么制作來(lái)回?fù)u擺的花朵的動(dòng)畫(huà)?
Flash怎么制作來(lái)回?fù)u擺的花朵的動(dòng)畫(huà)?Flash中想要給花朵制作一段搖擺的動(dòng)畫(huà)效果,該怎么制作呢?下面我們就來(lái)看看詳細(xì)的教程,很簡(jiǎn)單,需要的朋友可以參考下2017-05-23
Flash怎么制作流動(dòng)七彩色的文字?想要讓文字動(dòng)起來(lái),該怎么使用flash給文字制作一個(gè)流動(dòng)七彩色的動(dòng)畫(huà)呢?下面我們就來(lái)看看詳細(xì)的教程,需要的朋友可以參考下2017-04-23











