Spriteで雨。

by yuugurenote
♥0 | Line 97 | Modified 2012-06-19 16:07:54 | MIT License
play

ActionScript3 source code

/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kIrT
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
    public class AS120619_01 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var _myLine1:myLine1;
        public var _myLine2:myLine2;
        public var _myLine3:myLine3;
        public var _myLine4:myLine3;
        public var _myLine5:myLine5;
        public var _myRain:myRain;
        public var max:uint=50;
        public var xnMax:Number = 390;
        public var xnMin:Number = 70;
        public var ynMax:Number = 380;
        public var ynMin:Number = 120;

        public function AS120619_01() {

            _myLine1 = new myLine1();
            _myLine1.x=82.5;
            _myLine1.y=50;
            addChild(_myLine1);

            _myLine2 = new myLine2();
            _myLine2.x=57.5;
            _myLine2.y=110;
            addChild(_myLine2);

            _myLine3 = new myLine3();
            _myLine3.x=57.5;
            _myLine3.y=110;
            addChild(_myLine3);

            _myLine4 = new myLine3();
            _myLine4.x=407.5;
            _myLine4.y=110;
            addChild(_myLine4);

            for (var i:uint=0; i<max; i++) {
                _myRain = new myRain();
                _myRain.x=Math.floor(Math.random()*(xnMax-xnMin+1))+xnMin;
                _myRain.y=Math.floor(Math.random()*(ynMax-ynMin+1))+ynMin;
                addChild(_myRain);

            }
            _myLine5 = new myLine5();
            _myLine5.x=230;
            _myLine5.y=60;
            addChild(_myLine5);

        }

    }
}

import flash.display.Sprite;
import flash.events.Event;
class myLine1 extends Sprite {
    public function myLine1() {
        this.graphics.lineStyle(10,0x000000,1,false,"none");
        this.graphics.beginFill(0x333333,1);
        this.graphics.drawRect(0,0,300,10);
        this.graphics.endFill();
    }
}
class myLine2 extends Sprite {
    public function myLine2() {
        this.graphics.lineStyle(10,0x000000,1,false,"none");
        this.graphics.beginFill(0x333333,1);
        this.graphics.drawRect(0,0,350,10);
        this.graphics.endFill();
    }
}
class myLine3 extends Sprite {
    public function myLine3() {
        this.graphics.lineStyle(10,0x000000,1,false,"none");
        this.graphics.beginFill(0x333333,1);
        this.graphics.drawRect(0,0,10,280);
        this.graphics.endFill();
    }
}
class myLine5 extends Sprite {
    public function myLine5() {
        this.graphics.lineStyle(10,0x000000,1,false,"none");
        this.graphics.beginFill(0x333333,1);
        this.graphics.drawRect(0,0,10,330);
        this.graphics.endFill();
    }
}
class myRain extends Sprite {
    public function myRain() {
        this.graphics.beginFill(0x0066FF,1);
        this.graphics.drawRect(0,0,2,30);
        this.graphics.endFill();
        this.addEventListener(Event.ENTER_FRAME,xEnter);
    }
    public function xEnter(e:Event):void {
        this.y+=Math.floor(Math.random() * 7)+3;
        if (this.y>=380) {
            this.y=120;
        }
    }
}

Forked