粒子爆炸效果
发布时间:2020-12-15 06:47:08 所属栏目:百科 来源:网络整理
导读:数学公式: var angle:Number = Math.atan2(y,x); ball.x += Math.cos(angle) * vx; ball.y += Math.sin(angle) * vy; ? 首先自己在flash里面画个Ball ? 以下是源码: package {import flash.display.MovieClip;import flash.display.DisplayObject;import f
数学公式: var angle:Number = Math.atan2(y,x); ? 首先自己在flash里面画个Ball ? 以下是源码:
package { import flash.display.MovieClip; import flash.display.DisplayObject; import flash.events.*; import flash.system.System; import net.hires.debug.Stats; [SWF(width = "700",height = "480",frameRate = "25",backgroundColor = "0x000000")] /** * ... * @author Li灬Star * @contact QQ:168527720 */ public class LiZi extends MovieClip { private var container:MovieClip = new MovieClip(); private static const NUM:int = 400; public function LiZi() { init(); } private function init():void { addChild(new Stats()); this.addChild(container); stage.addEventListener(MouseEvent.MOUSE_DOWN,downHandler); } private function downHandler(e:MouseEvent):void { for (var i:int = 0; i < NUM; i++ ) { var ball:Ball = new Ball(); container.addChild(ball); ball.x = mouseX; ball.y = mouseY; //--------------------->定义每个ball的x,y速度 ball.vx = Math.random() * 4 + 2; ball.vy = Math.random() * 5 + 2; //---------------------->定义每个ball运动的方向角度 var angle:Number = Math.atan2(Math.random() * 480 - ball.y,Math.random() * 700 - ball.x);//随机一个角度,返回的值为弧度 ball.angle = angle; ball.addEventListener(Event.ENTER_FRAME,enterFrameHandler); } } private function enterFrameHandler(e:Event):void { e.currentTarget.x += Math.cos(e.currentTarget.angle) * e.currentTarget.vx; e.currentTarget.y += Math.sin(e.currentTarget.angle) * e.currentTarget.vy; if (e.currentTarget.x<0||e.currentTarget.x>stage.stageWidth|| e.currentTarget.y<0||e.currentTarget.y>stage.stageHeight ) { e.currentTarget.removeEventListener(Event.ENTER_FRAME,enterFrameHandler); var obj:DisplayObject = e.currentTarget as DisplayObject; container.removeChild(obj); obj = null; System.gc(); } } } } ? ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |