あなたが今、抱えてる悩み カンドウコーポレーションが解決します お悩み一掃!!
STAFF INFORMATION

フラッシュ・ラボ バウンド処理[クラス型] [柳谷 武]

スタッフ紹介 >> 柳谷 武 >> フラッシュ・ラボ >> バウンド処理[クラス型]  
<< 前に戻る  
[オブジェクトの色別に弾みの量を変える]GRAVITY
オブジェクトの弾む量を、色が明るい程よく弾むように変更。
オブジェクトをドラッグして、放り投げれます。
オブジェクトの色別に弾みの量を変える

[7]オブジェクトの色の種類が10種類あります。
フレーム数が大きいほど、明るい色になるようになっています。色の種類を設定する変数を使って、0〜this.bound〜1以下の数値がランダムで設定されるようにスクリプトを変更。
赤字は、前回から追加したり変更したりした部分です。

[ スクリプト - ツクリカタ ]

[A] ライブラリに準備するもの

   ・追加は特になし。

ではまず、フラッシュの実行が始まる最初のフレームにスクリプトを記述します。


初期定義

MovieClip.prototype.obj = function() {

};

obj.prototype = new MovieClip();

obj.prototype.onLoad = function() {

  //落下設定初期値

  this.ySpeed = 0;

  this.ySpeedAdd = 4;

  this.xSpeed = random(100);

  this.xSpeedAdd = 0;

  this.bound_kinds = random(10)+1;

  this.bound = (this.bound_kinds+8)/(20);

  this.gotoAndStop(this.bound_kinds);

};

初期定義 マウスクリック関係

obj.prototype.onPress = function(){

  this.drag_sw = 1

  //最前面へ

  _root.depth_num ++

  _root[this.num].swapDepths(_root.depth_num)

}

obj.prototype.onRelease = obj.prototype.onReleaseOutside = function(){

  this.drag_sw = 0

  //ほおり投げる

  this.xSpeed = this.xSub

  this.ySpeed = this.ySub

}



繰り返し処理

obj.prototype.onEnterFrame = function() {

  if( this.drag_sw == 1 ){//ドラッグ中

    this.xSub = (_root._xmouse - this._x)/2

    this.ySub = (_root._ymouse - this._y)/2

    this._x += this.xSub

    this._y += this.ySub

  }else{//ドラッグしていないとき

    //落下設定

    this.ySpeed += this.ySpeedAdd;//加速

    this._y += this.ySpeed;

    this._x += this.xSpeed;

  }

  //着地判定

  if (this._y+(this._height/2)>100) {

    //地面に当たったら

    this._y -= (this._y+(this._height/2))-100;

    //地面を軸に座標を反転

    if (this.ySpeed>0.05) {

      //バウンドの力で判断

      this.ySpeed *= -this.bound;

      this.xSpeed *= this.bound;

    } else {

      //バウンドが弱まったら

      delete this.onEnterFrame;//処理をとめる

    }

  }

  //壁判定

  if (this._x-(this._width/2)<0 ){

    //左の壁を軸に座標を反転
    this._x -= (this._x-(this._width/2)) - 0;
    

    this.xSpeed *= -(1-this.bound);

    this.ySpeed *= 1-this.bound;

  }

  if (this._x+(this._width/2)>100 ){

    //右の壁を軸に座標を反転
    this._x -= (this._x+(this._width/2)) -100;
    

    this.xSpeed *= -(1-this.bound);

    this.ySpeed *= 1-this.bound;

  }

};
Object.registerClass("objjects", obj);



初期処理

_root.obj_max = _root.depth_num = 4;

for (i=0; i<obj_max; i++) {

  attachMovie("objjects", i, i);

  this[i].num = i;

  this[i]._x = random(50);

  this[i]._y = -random(200);

  this[i]._xscale = this[i]._yscale = random(100)+100;

}


※上記のスクリプトには、全角スペースが含まれています。
コピペで使う場合、エラーが起こってしまうので、TABで行を右にずらす作業をやり直す必要があります。


[ スクリプトの意味 ]

初期定義
●this.bound = (this.bound_kinds+8)/(20);
壁や地面に衝突したときのバウンドの低下率が0.45〜0.9の中からランダムで設定されるよう変更。



<< 前に戻る