CocosCreator:常用于动画的缓动类Easing
定义:以非线性的方式修改值的函数,通常用于动画。
在cocoscreator中有easing各字段的属性,预定义的 Easing 函数具有以下形式:
字段:
BounceIn:

BounceOut:

CubicIn:

CubicInOut:

CubicOut:

Linear:

SinIn:

SinInOut:

SinOut:

SpringIn:

SpringOut:

当然还有很多,cocosCreator内置了这些函数,可以直接在tween中使用

cocoscreator3.x的api个人看起来很费劲,所以还是到2.x中去扒
Easing:缓动函数类,为 Tween 提供缓动效果函数
关于这些缓动函数的效果:cocoscreator2.x还提供了效果图:
https://easings.net/cn
文档说明也很详细:https://docs.cocos.com/creator/2.3/api/zh/classes/Easing.html?h=easing
使用 easing 来使缓动更生动,cc.tween
针对不同的情况提供了多种使用方式:
// 传入easing名字,直接使用内置easing函数
cc.tween().to(1, { scale: 2 }, {easing: 'sineOutIn'})
// 使用自定义easing函数
cc.tween().to(1, { scale: 2 }, {easing: t => t*t; })
// 只对单个属性使用easing函数// value 必须与easing或者 progress 配合使用
cc.tween().to(1, { scale: 2, position: { value: cc.v3(100, 100, 100),easing: 'sineOutIn' } })
相对于 easing,自定义 progress 函数可以更自由的控制缓动的过程:
// 对所有属性自定义 progress
cc.tween().to(1, { scale: 2, rotation: 90 },
{
progress: (start, end, current, ratio) => {
return start + (end - start) * ratio;
}
})
// 对单个属性自定义 progress
cc.tween().to(1, {
scale: 2,
position: {
value: cc.v3(),
progress: (start, end, current, t) => {
return start.lerp(end, t, current);
}
}
}
)
// 注意,传入的属性为 cc.Vec3,所以需要使用 Vec3.lerp 进行插值计算