flash中落花效果AS3实现代码

作者:袖梨 2022-06-28

以下为flash落花效果的as3代码,如要欣赏FLASH动画效果请见本文底部的动画演示。

 代码如下 复制代码

function flower():Sprite {
var mc:Sprite=new Sprite();
var color:uint=Math.random()*0x88ffff+0x880000;
var num:int=int(Math.random()*9+1);
var i:int=0;
while (i++ var huaBan:Shape=new Shape();
huaBan.graphics.beginGradientFill(GradientType.RADIAL,[0xffffff,color],[0.6,1],[0,255]);
huaBan.graphics.moveTo(0,0);
huaBan.graphics.curveTo(30,-45,0,-50);
huaBan.graphics.curveTo(-30,-45,0,0);
huaBan.rotation=360/num*i;
mc.addChild(huaBan);
}
return mc;
}
//画花函数//www.111com.net
var mcNum:int=50;//花的数量
var mcArr:Array=[];//存储花的数组
var vxArr:Array=[];//x速度数组
var vyArr:Array=[];//y速度数组
var vrArr:Array=[];//旋转速度数组
var clickCount:int=0;//点击次数
for (var i:int=0; i var mc:Sprite=flower();
addChild(mc);
mc.scaleX=mc.scaleY=0.2+Math.random()*0.5;
mc.x=Math.random()*stage.stageWidth;
mc.y=-Math.random()*stage.stageHeight;
vxArr.push(Math.random()*2-1);
vyArr.push(Math.random()*2+2);
vrArr.push(Math.random()*4-2);
mcArr.push(mc);
}
addEventListener(Event.ENTER_FRAME,frame);
function frame(e:Event):void {
for (i=0; i mcArr[i].x+=vxArr[i];
mcArr[i].y+=vyArr[i];
mcArr[i].rotation+=vrArr[i];
if (mcArr[i].y>stage.stageHeight+mcArr[i].width/2) {
mcArr[i].x=Math.random()*stage.stageWidth;
mcArr[i].y=-Math.random()*stage.stageHeight;
}
}
}
stage.addEventListener(MouseEvent.CLICK,onClick);
function onClick(e:MouseEvent):void {
if (clickCount++%2==0) {
removeEventListener(Event.ENTER_FRAME,frame);
} else {
addEventListener(Event.ENTER_FRAME,frame);
}
}

相关文章

精彩推荐