CocosCreator:常用于動(dòng)畫的緩動(dòng)類Easing
定義:以非線性的方式修改值的函數(shù),通常用于動(dòng)畫。
在cocoscreator中有easing各字段的屬性,預(yù)定義的?Easing?函數(shù)具有以下形式:
字段:
BounceIn:

BounceOut:

CubicIn:

CubicInOut:

CubicOut:

Linear:

SinIn:

SinInOut:

SinOut:

SpringIn:

SpringOut:
????

當(dāng)然還有很多,cocosCreator內(nèi)置了這些函數(shù),可以直接在tween中使用

cocoscreator3.x的api個(gè)人看起來(lái)很費(fèi)勁,所以還是到2.x中去扒
Easing:緩動(dòng)函數(shù)類,為?Tween?提供緩動(dòng)效果函數(shù)
關(guān)于這些緩動(dòng)函數(shù)的效果:cocoscreator2.x還提供了效果圖:
https://easings.net/cn
文檔說(shuō)明也很詳細(xì):https://docs.cocos.com/creator/2.3/api/zh/classes/Easing.html?h=easing
使用?easing?來(lái)使緩動(dòng)更生動(dòng),cc.tween
?針對(duì)不同的情況提供了多種使用方式:
// 傳入easing名字,直接使用內(nèi)置easing函數(shù)
cc.tween().to(1, { scale: 2 }, {easing: 'sineOutIn'})
// 使用自定義easing函數(shù)
cc.tween().to(1, { scale: 2 }, {easing: t => t*t; })
// 只對(duì)單個(gè)屬性使用easing函數(shù)// value 必須與easing或者 progress 配合使用
cc.tween().to(1, { scale: 2, position: { value: cc.v3(100, 100, 100),easing: 'sineOutIn' } })
相對(duì)于?easing,自定義 progress 函數(shù)可以更自由的控制緩動(dòng)的過(guò)程:
// 對(duì)所有屬性自定義 progress
cc.tween().to(1, { scale: 2, rotation: 90 },?
{
?
progress: (start, end, current, ratio) => { ? ?
????return start + (end - start) * ratio;
?
????}?
})
// 對(duì)單個(gè)屬性自定義 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 進(jìn)行插值計(jì)算?