欢迎光临散文网 会员登陆 & 注册

CocosCreator:常用于动画的缓动类Easing

2021-12-01 17:24 作者:会飞的蜗牛007  | 我要投稿

定义:以非线性的方式修改值的函数,通常用于动画。

在cocoscreator中有easing各字段的属性,预定义的 Easing 函数具有以下形式:

字段:

BounceIn:

跳转到最终值,然后退回,最后确定最终值

BounceOut:

跳转至最终值,退回 3 次,然后确定

CubicIn:

启动缓慢,然后逐渐加速

CubicInOut:

加速和减速。 通常是一个看起来正常的选择

CubicOut:

快速启动,然后减速

Linear:

线性转换

SinIn:

平稳加速

SinInOut:

加速进入,减速退出

SinOut:

平稳减速

SpringIn:

移动,然后跳转至最终值

SpringOut:

    

迭代过度,然后返回

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

creator3.2的API

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 进行插值计算 


CocosCreator:常用于动画的缓动类Easing的评论 (共 条)

分享到微博请遵守国家法律