Crafty.easing

一个跟踪过渡的对象。通常通过 "SpriteAnimation", "Tween",或者视口动画间接使用。

如果一个方法允许你指定过渡类型,你可以使用一个自定义的函数或者一个内置方法名称对应的字符串来实现。

内置的过渡函数有 "linear", "smoothStep", "smootherStep", "easeInQuad", "easeOutQuad", 和 "easeInOutQuad".

一个自定义函数将传递一个参数t,该值在0到1之间变化,并且应该返回一个0到1之间的值来表示动画进度。

例子

这里是结合 “Tween” 组件使用过渡函数的例子。

var e = Crafty.e("2D, Tween");
// Use built-in easing functions
e.tween({x:100}, 1000, "smoothStep");
e.tween({y:100}, 1000, "easeInQuad");
// Define a custom easing function: 2t^2 - t
e.tween({w:0}, 1000, function(t){return 2*t*t - t;});