Ex06_ex02
♥0 |
Line 39 |
Modified 2011-07-06 16:10:07 |
MIT License
archived:2017-03-20 08:04:10
ActionScript3 source code
/**
* Copyright s1190133 ( http://wonderfl.net/user/s1190133 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9VEB
*/
package {
import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Sprite;
[SWF(width=465,height=465,backgroundColor=0x000000)]
public class Ex06_ex02 extends Sprite {
private var arr:Array=[];
private var ball:Ball;
public function Ex06_ex02() {
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
for(var i:int=0;i<20;i++){
ball=new Ball;
arr[i]=ball;
ball.x=stage.stageWidth/2; //ステージの高さと幅の半分にすることで中央に
ball.y=stage.stageHeight/2;
addChild(ball);
}
//こいつが見張ってます
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
//こいつが動かしてくれます
private function onEnterFrame(e:Event):void{
for(var i:int=0;i<20;i++){
//x方向とy方向に速度を足してく
arr[i].x+=arr[i].vx;
arr[i].y+=arr[i].vy;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var vx:Number=Math.random()*10-5; //なぜここを10-5にするのか考えとくこと
public var vy:Number=Math.random()*10-5;
public function Ball(){ //ボールを描きます
graphics.beginFill(0xFFFFFF*Math.random());
graphics.drawCircle(0,0,10);
graphics.endFill();
}
}