简体   繁体   English

如何将Greensock的CustomEase函数转换为可在CreateJS的Tween系统中使用?

[英]How to convert Greensock's CustomEase functions to be usable in CreateJS's Tween system?

I'm currently working on a project that does not include GSAP (Greensock's JS Tweening library), but since it's super easy to create your own Custom Easing functions with it's visual editor - I was wondering if there is a way to break down the desired ease-function so that it can be reused in a CreateJS Tween? 我目前正在从事一个不包含GSAP(Greensock的JS补间库)的项目,但是由于使用可视化编辑器创建自己的自定义缓动功能非常容易-我想知道是否有一种方法可以分解期望的easy-function,以便可以在CreateJS Tween中重用?

Example: 例:

var myEase = CustomEase.create("myCustomEase", [
    {s:0,cp:0.413,e:0.672},{s:0.672,cp:0.931,e:1.036},
    {s:1.036,cp:1.141,e:1.036},{s:1.036,cp:0.931,e:0.984},
    {s:0.984,cp:1.03699,e:1.004},{s:1.004,cp:0.971,e:0.988},
    {s:0.988,cp:1.00499,e:1}
]);

So that it turns it into something like: 这样它就变成了类似:

var myEase = function(t, b, c, d) {
    //Some magic algorithm performed on the 7 bezier/control points above...
}

( Here is what the graph would look like for this particular easing method. ) 这是该特定宽松方法的图形外观。 在此处输入图片说明

I took the time to port and optimize the original GSAP-based CustomEase class... but due to license restrictions / legal matters ( basically a grizzly bear that I do not want to poke with a stick... ), posting the ported code would violate it. 我花了一些时间移植和优化原始的基于GSAP的CustomEase类...但是由于许可证限制/法律问题( 基本上是灰熊,我不想用棍子戳... ),发布了移植的代码会违反它。

However, it's fair for my own use. 但是,这对于我自己使用是公平的。 Therefore, I believe it's only fair that I guide you and point you to the resources that made it possible. 因此,我相信引导您并指出使之成为可能的资源是公平的。

The original code (not directly compatible with CreateJS) can be found here: https://github.com/art0rz/gsap-customease/blob/master/CustomEase.js ( looks like the author was also asked to take down the repo on github - sorry if the rest of this post makes no sense at all! ) 原始代码(与CreateJS不直接兼容)可以在以下位置找到: https : //github.com/art0rz/gsap-customease/blob/master/CustomEase.js看起来作者也被要求撤回该仓库github-很抱歉,如果本文的其余部分毫无意义!

Note that CreateJS's easing methods only takes a "time ratio" value (not time, start, end, duration like GSAP's easing method does). 请注意,CreateJS的缓动方法仅采用“时间比率”值(而不是time, start, end, duration就像GSAP的缓动方法一样)。 That time ratio is really all you need, given it goes from 0.0 (your start value) to 1.0 (your end value). 该时间比例实际上是您所需的,因为它从0.0 (您的起始值)到1.0 (您的终止值)。

With a little bit of effort, you can discard those parameters from the ease() method and trim down the final returned expression. 只需花费一点力气,您就可以从ease()方法中丢弃这些参数,并修剪最终返回的表达式。

Optimizations: 优化:

I took a few extra steps to optimize the above code. 我采取了一些额外的步骤来优化上述代码。

1) In the constructor, you can store the segments.length value directly as this.length in a property of the CustomEase instance to cut down a bit on the amount of accessors / property lookups in the ease() method (where qty is set). 1)在构造函数中,您可以将segments.length值直接作为this.length存储在CustomEase实例的属性中,以减少easy ease()方法(其中设置了qty ease()中访问器/属性查找的qty )。

2) There's a few redundant calculations done per Segments that can be eliminated in the ease() method. 2)每个细分市场都有一些多余的计算,可以通过ease()方法消除这些计算。 For instance, the s.cp - ss and se - ss operations can be precalculated and stored in a couple of properties in each Segments (in its constructor). 例如,可以预先计算s.cp - ssse - ss s.cp - ss操作并将其存储在每个Segment中的几个属性中(在其构造函数中)。

3) Finally, I'm not sure why it was designed this way, but you can unwrap the function() {...}(); 3)最后,我不确定为什么要这样设计,但是您可以打开function() {...}(); that are returning the constructors for each classes. 返回每个类的构造函数。 Perhaps it was used to trap the scope of some variables, but I don't see why it couldn't have wrapped the entire thing instead of encapsulating each one separately. 也许它被用来捕获某些变量的范围,但是我不明白为什么它不能包装整个东西,而不是分别封装每个东西。

Need more info? 需要更多信息? Leave a comment! 发表评论!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM