Created
December 28, 2013 04:45
-
-
Save sebbdk/8156192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dk.sebb.scenes | |
| { | |
| import flash.display.Bitmap; | |
| import flash.display.MovieClip; | |
| import flash.events.Event; | |
| import flash.geom.Point; | |
| /** | |
| * ... | |
| * @author Sebb | |
| */ | |
| public class Rain extends MovieClip | |
| { | |
| private var particles:Vector.<Bitmap> = new Vector.<Bitmap>(); | |
| private var inertia:Point; | |
| public function Rain() | |
| { | |
| inertia = new Point(2, 6); | |
| addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); | |
| addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage); | |
| } | |
| private function onAddedToStage(evt:Event):void { | |
| addEventListener(Event.ENTER_FRAME, onEnterFrame); | |
| build(); | |
| } | |
| private function onRemovedFromStage(evt:Event):void { | |
| removeEventListener(Event.ENTER_FRAME, onEnterFrame); | |
| } | |
| public function build():void { | |
| while (particles.length < 100) { | |
| var particle:Bitmap = Assets.getBitmap('drop01'); | |
| particle.x = Math.random() * stage.stageWidth; | |
| particle.y = Math.random() * stage.stageHeight; | |
| particles.push(particle); | |
| addChild(particle); | |
| } | |
| } | |
| public function onEnterFrame(evt:Event):void { | |
| for each(var part:Bitmap in particles) { | |
| part.x += inertia.x; | |
| part.y += inertia.y; | |
| if (part.y > stage.stageHeight) { | |
| part.y = -40; | |
| } | |
| if (part.x > stage.stageWidth) { | |
| part.x = 1; | |
| } | |
| if (part.x < 0) { | |
| part.x = stage.stageWidth - 1; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment