zoukankan      html  css  js  c++  java
  • 下雪效果

    displaySnow();
    
    function displaySnow() {
    	for (var i:int=0; i<40; i++) {
    		var snowFlake:SnowFlake=new SnowFlake(400);
    		addChild(snowFlake);
    
    		snowFlake.x=Math.random()*550;
    		snowFlake.y=Math.random()*400;
    
    		snowFlake.alpha=0.2+Math.random()*5;
    
    		snowFlake.scaleX=snowFlake.scaleY=0.4+Math.random()*1.5;
    	}
    }
    
    //===================雪花类SnowFlake.as===================
    package {
    	import flash.display.MovieClip;
    	import flash.events.Event;
    
    	public class SnowFlake extends MovieClip {
    		private var radians:Number=0;
    		private var speed:Number=0;
    
    		private var maxHeight:Number;
    
    		public function SnowFlake(maxHeight_:Number) {
    			speed=0.5*Math.random();//[0.01,0.51)
    
    			maxHeight=maxHeight_;
    
    			this.addEventListener(Event.ENTER_FRAME,snowing);
    		}
    
    		private function snowing(e:Event):void {
    			radians+=speed;
    
    			//如果此处不用Math.cos(),而用普通的this.x+=Math.random()*2,左右晃动效果会很明显
    			this.x+=Math.cos(radians);
    			this.y+=2;
    
    			if (this.y>maxHeight) {
    				this.y=-20;
    			}
    		}
    	}
    }
    
  • 相关阅读:
    关押罪犯
    食物链
    归并排序(分治)
    并查集+路径压缩
    3的幂的和
    斐波那契数列的第N项
    0和5
    扔盘子
    线段相交
    回文字符串
  • 原文地址:https://www.cnblogs.com/leon3286/p/1807203.html
Copyright © 2011-2022 走看看