moveBalls
ボールを動かす
♥0 |
Line 41 |
Modified 2010-08-19 21:51:32 |
MIT License
archived:2017-03-20 09:23:47
ActionScript3 source code
/**
* Copyright you_KAZE ( http://wonderfl.net/user/you_KAZE )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/88qh
*/
//ボールを動かす
package {
import flash.display.*;
import flash.events.Event;
[SWF(frameRate="30",width="200",height="200")]
public class FlashTest extends Sprite {
private var _circle:Circle;
public function FlashTest() {
_circle = new Circle(10,0x005566);
_circle.alpha=0.25;
_circle.vx=3;
_circle.vy=4;
_circle.x=Math.random()*200;
_circle.y=Math.random()*200;
addChild(_circle);
addEventListener(Event.ENTER_FRAME,enterFrame);
}
private function enterFrame(e:Event):void{
_circle.move();
}
}
}
import flash.display.Sprite;
class Circle extends Sprite{
//move X,Y
public var vx:Number;
public var vy:Number;
//circle radius
public var radius:Number;
//コンストラクタ:初期設定
public function Circle(_radius:Number,_fillColor:uint=0x000000){
//Fill:_fillColor,radius:_radius
graphics.beginFill(_fillColor);
graphics.drawCircle(0,0,_radius);
graphics.endFill();
//パブリックな変数に変換
radius=_radius;
}
//ボールにおける1フレーム分の処理
public function move():void{
x += vx;
y += vy;
if(x<0){x=0;vx*=(-0.7);}
if(x>200){x=200;vx*=(-0.7);}
if(y<0){y=0;vy*=(-0.7);}
if(y>200){y=200;vy*=(-0.7);}
}
}