落下運動3 : ActionScript
反発係数を考慮した落下運動のサンプル。
シンボル — リンケージ:ball, 幅:10,高さ:10,中心:(-5,-5)
function Ball() {
// 初期位置
this._x = Stage.width/2;
this._y = 0;
// 半径
var radius = 5;
// 速度
var vy = 10;
// 加速度
var a = 0.98
// 反発係数
var e = 0.85;
// イベントハンドラ
this.onEnterFrame = function() {
// 等加速度落下
vy += a;
this._y += vy;
// 跳ね返り
if (this._y+radius>Stage.height) {
this._y = Stage.height-radius;
// 弾性衝突
vy *= -e;
}
};
}
var o = new Ball();
var mc = attachMovie("ball", "ball", 0, o);
コメントはまだありません。
コメントの投稿
改行と段落タグは自動で挿入されます。メールアドレスは表示されません。
利用可能な HTML タグ :
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite="">
<cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>