phaser/src/tweens/builders/GetEaseFunction.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
var EaseMap = require('../../math/easing/EaseMap');
2018-02-10 17:11:36 +00:00
/**
* [description]
*
* @function Phaser.Tweens.Builders.GetEaseFunction
* @since 3.0.0
*
2018-03-20 15:12:42 +00:00
* @param {(string|function)} ease - [description]
2018-02-10 17:11:36 +00:00
* @param {array} easeParams - [description]
*
* @return {function} [description]
*/
var GetEaseFunction = function (ease, easeParams)
{
// Default ease function
var easeFunction = EaseMap.Power0;
// Prepare ease function
if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease))
{
// String based look-up
easeFunction = EaseMap[ease];
}
else if (typeof ease === 'function')
{
// Custom function
easeFunction = ease;
}
else if (Array.isArray(ease) && ease.length === 4)
{
// Bezier function (TODO)
}
// No custom ease parameters?
if (!easeParams)
{
// Return ease function
return easeFunction;
}
var cloneParams = easeParams.slice(0);
cloneParams.unshift(0);
// Return ease function with custom ease parameters
return function (v)
{
cloneParams[0] = v;
return easeFunction.apply(this, cloneParams);
};
};
module.exports = GetEaseFunction;