我正在研究在java应用程序中使用的jquery java函数,并以此作为结束:
// 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。我如何提供函数?
发布于 2011-02-06 12:02:23
这基本上是psuedo-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);
}
}你可能想要根据你的设置来移动东西,但是这就是你如何使用这种放松方程的方式。
https://stackoverflow.com/questions/4911096
复制相似问题