Hatena::ブログ(Diary)

uncertain world

2009-01-12

ActionScriptの練習2

| 20:11 | ActionScriptの練習2を含むブックマーク ActionScriptの練習2のブックマークコメント

今度はお星様。


レイヤ

// お星様
for (i=1;i<50;i++) {
	this.star0.duplicateMovieClip('star'+i, i);
}


・星オブジェクト側(star0)

onClipEvent(load) {
	// 配置座標
	this._x = Math.random() * Stage.width;
	this._y = Math.random() * Stage.height;
	// 透明度
	this._alpha = 50 + Math.random() * 20;
	// 倍率
	this._xscale =  this._yscale = 50 + Math.random() * 50;
	// 中心からの距離
	distance_from_center = Math.sqrt(
		(200 - this._x) * (200 - this._x) + (200 - this._y) * (200 - this._y)
	);
	// 現在の角度
	rad = Math.random() * 360;
}

onClipEvent(enterFrame) {
	// 中心からの距離がdistance_from_centerで一度ずつズレてく
	rad += 1;
	this._x = Math.cos((rad/180) * Math.PI) * distance_from_center + 200;
	this._y = Math.sin((rad/180) * Math.PI)  * distance_from_center + 200;
}


三角関数だよ!全員集合!><

次は砂時計作りたいなぁ。

トラックバック - http://d.hatena.ne.jp/rin1024/20090112/1231758678