除了可以改变粒子的运动速度之外,还可以改变它的大小,通过设置它的growX和growY属性就可以达到目的。
2 | import flash.display.Sprite; |
3 | import flash.events.Event; |
5 | [SWF(width= "800" ,height= "600" ,backgroundColor= "0xffffff" ,frameRate= "31" )] |
6 | public class ParticleGrow extends Sprite{ |
7 | private var numbers: Number = 20 ; |
8 | private var particles: Array ; |
10 | public function ParticleGrow(){ |
11 | particles= new Array (); |
12 | stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); |
15 | private function onEnterFrame(e:Event): void { |
16 | if (particles.length < numbers){ |
17 | var ball:Ball= new Ball( 12 , 0x00ff00 , 1 , 0x000000 , 1 ); |
19 | ball.xVelocity=Math.random() * 20 - 10 ; |
20 | ball.yVelocity=Math.random() * 20 - 10 ; |
24 | ball.x=stage.stageWidth/ 2 ; |
25 | ball.y=stage.stageHeight/ 4 ; |
28 | for ( var i: int = 0 ; i < particles.length; i++){ |
29 | var particle:Ball=particles[i]; |
31 | if (particle.x - particle.radius > stage.stageWidth || particle.x + particle.radius < 0 || particle.y - particle.radius > stage.stageHeight || particle.y + particle.radius < 0 ){ |
32 | particle.xVelocity=Math.random() * 20 - 10 ; |
33 | particle.yVelocity=Math.random() * 20 - 10 ; |
34 | particle.x=stage.stageWidth / 2 ; |
35 | particle.y=stage.stageHeight / 4 ; |
36 | particle.scaleX = particle.scaleY = 1 ; |
代码将ball粒子的growX和growY设置为1.05,从而实现逐帧放大的效果。当超过环境边界之后,再将它的scaleX和scaleY设置设置为1,恢复它原始的大小。

转载请注明:陈童的博客 » 缩放粒子