snow flies, use to Z axis : flash on 2010-2-13
@author Yoshi
♥0 |
Line 53 |
Modified 2010-02-13 10:22:26 |
MIT License
archived:2017-03-20 01:32:19
ActionScript3 source code
/**
* Copyright hazel_eyes ( http://wonderfl.net/user/hazel_eyes )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6hpb
*/
package {
/**
* @author Yoshi
*/
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Transform;
import flash.geom.Point;
import flash.geom.PerspectiveProjection;
import flash.display.GradientType;
[SWF(backgroundColor=0x111111,frameRate=20)]
public class snowMain extends Sprite {
public function snowMain(){
root.transform.perspectiveProjection.projectionCenter = new Point(0, -1000);
this.addEventListener(Event.ENTER_FRAME, snowCopy);
}
private function snowCopy(evt:Event):void {
var mtrx:Matrix = new Matrix();
mtrx.createGradientBox(12, 12, 0, -5, -5);
var snow_sp:snowMove = new snowMove();
snow_sp.graphics.beginGradientFill(GradientType.RADIAL, [0xffffff, 0xffffff], [1, 0], [0, 255], mtrx);
snow_sp.graphics.drawCircle(0, 0, 12);
snow_sp.graphics.endFill();
snow_sp.x = Math.random()*stage.stageWidth;
snow_sp.y = -Math.random()*50;
var zNum:Number = Math.random();
snow_sp.z = -(zNum*1800-400);
snow_sp.alpha = 1-zNum*0.6;
snow_sp.yVel = 1.6*(zNum*2.0+1);
snow_sp.xVel = 0.5+zNum*1;
stage.addChild(snow_sp);
}
}
}
import flash.display.Sprite;
import flash.events.Event;
/**
* @author Yoshi
*/
class snowMove extends Sprite
{
public var yVel:Number;
public var xVel:Number;
private var xRandom:Number;
public function snowMove()
{
this.addEventListener(Event.ENTER_FRAME,snowComeDown);
}
public function snowComeDown(evt:Event):void {
if(this.y > stage.stageHeight+this.height){
this.removeEventListener(Event.ENTER_FRAME,snowComeDown);
stage.removeChild(this);
}
xRandom = Math.random()*xVel*2-xVel;
this.x += xRandom;
this.y += yVel;
}
}