2009-01-12
ActionScriptの練習
・レイヤ側
var id = 0;
// 雪生成
for (id=0; id<20; id++) {
this.snow0.duplicateMovieClip('snow'+id, id);
}
// 少しずつ増えていきます
var snowObserver = setInterval(function() {
if (Math.random() * 10 < 1) {
snow.duplicateMovieClip('snow'+(++id), id, {_y:0});
//trace('create new snow id : ' + id);
}
if (id >= 200)
clearInterval(snowObserver);
}, 500);
・雪オブジェクト側(snow0)
onClipEvent (load) {
// 落下角度
fallangle = -Math.PI + Math.random() * Math.PI ;
// 落下方向(左右)
falldirection = Math.random() * 1 - 1;
// 倍率
this._xscale = this._yscale = 50 + Math.random() * 70;
// 落下速度(倍率が高いほど速度も上昇)
fallspeed = 1 + Math.random() * 2 + this._xscale / 60;
// 初期位置
this._x = Math.random() * Stage.width;
this._y = Math.random() * Stage.height;
// 透過度
this._alpha = 60 + Math.random() * 40;
}
onClipEvent (enterFrame) {
// 横軸
rad = (fallangle / 180) * Math.PI ;
// trace(this + ' : ' + rad);
if (Math.random() * 1000 < 1)
falldirection = -falldirection;
this._x -= Math.cos(rad) * falldirection;
// 縦軸
if (Math.random() * 8)
this._y += fallspeed;
// 下まで行ったら上に戻る
if (this._y >= Stage.height || this._x >= Stage.width || this._x + this._width <= 0) {
this._x = Math.random() * Stage.width;
this._y = -10;
}
}
元が同じなだけに、JavaScriptと似てるけど、イベントハンドラの取得の仕方がちょっと違うんだなぁと感じた。
雪の落下のアルゴリズムは、下記のサイトを参考にさせていただきました。
コメントを書く
トラックバック - http://d.hatena.ne.jp/rin1024/20090112/1231733037
リンク元
- 7 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4GGIH_jaJP281JP282&q=SQL+Server2000+エラー SQL+Serverの信頼関係に関連付けら?
- 6 http://www.google.co.jp/search?hl=ja&q=このユーザーは+SQL+Server+の信頼関係接続と関連付けられて??
- 5 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=OVv&q=firefox3 落ちる&btnG=検索&lr=lang_ja
- 4 http://lab-works.no-ip.org/snow/
- 3 http://www.google.com/search?q=スクロールバー+クリック イベント&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7DBJP_ja
- 2 http://209.85.175.132/search?q=cache:-nVcsaRlrWkJ:d.hatena.ne.jp/rin1024/20080620/1213910268+firefox3+youtube+落ちる&hl=ja&ct=clnk&cd=4&gl=jp&lr=lang_ja&client=firefox-a
- 2 http://ezsch.ezweb.ne.jp/search/?sr=0101&query=ダイクストラ
- 2 http://mail.google.com/mail/?ui=2&view=bsp&ver=1qygpcgurkovy
- 2 http://www.google.co.jp/reader/view/?hl=ja&tab=wy
- 2 http://www.google.co.jp/search?hl=ja&q=フロイド法&lr=lang_ja
