java - Jquery 缓动函数

标签 java jquery easing

我正在研究在 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。我如何提供该功能?

最佳答案

这基本上是伪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);
  } 
}

您可能想要根据您的设置来移动事物,但这就是您使用这种缓动方程的方式。

关于java - Jquery 缓动函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4911096/

相关文章:

jquery - 以编程方式触摸屏幕 phonegap

jquery - Python & Selenium 无法在日期选择器中选择日期

javascript - 在特定时间后加载网址

javascript - 在鼠标按下控制时使用缓动效果向左/右动画 div

css - 如何创建 CSS 动画

java - 如何控制字符串迭代中分隔符(,)的添加

java - 用于在实体中存储 SQL ID 的选项

java - 对记录进行排序但在 Linux 和 Java 中将标题保持在顶部

jquery - 试图让填充和行高在 FF 中正确显示

java - 按 build.xml 依赖项拆分 Java 项目