0

私はJavaアプリケーションで使用するjqueryイージング関数を研究していて、これで終わりました:

// t: current time, b: begInnIng value, c: change In value, d: duration
    float easeInOutQuad (float x, float t, float b, float c, float d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    }

誰かがこれをアニメーション化された球体の動きに接続する方法を教えてもらえますか?

編集:球の動きを説明する不要なコードはここに入れません。このイージング関数を使用して、Xという名前のX位置を持つ球を想像してください。球は0から1000になります。関数をフィードするにはどうすればよいですか?

4

1 に答える 1

4

これは基本的に疑似 Java コードですが、テストしたところ動作します。球を使用する代わりに、小さな円を描きました。

Sphere sphere = new Sphere();

// you might want these to be in the sphere class
float begin;
float change;
float time;
long start;
float duration;
float destX = 200;

// setup, do this when you want to start the animation
void init(){
  begin = sphere.x;
  change = destX - begin;
  time = 0;
  start = System.currentTimeMillis();
  duration = 1000;
}

// loop code, may also be where you render the sphere
void loop(){
  if (time <= duration){
    sphere.x = easeInOutQuad(time, begin, change, duration);
  }else{
    // animation is over, stop the loop
  }
  time = System.currentTimeMillis() - start;
  sphere.render();
}

float easeInOutQuad (float t, float b, float c, float d) {
  if ((t/=d/2) < 1) return c/2*t*t + b;
  return -c/2 * ((--t)*(t-2) - 1) + b;
}

class Sphere{
  float x = 0;
  void render(){
    ellipse(x, 100, 10, 10);
  } 
}

セットアップによっては、おそらく物事を動かしたいと思うでしょうが、これはこのスタイルのイージング式を使用する方法です。

于 2011-02-06T04:02:23.360 に答える