Skip to content

Commit aad9d38

Browse files
committed
You can now specify easeParams for any custom easing function you wish to use. Fix phaserjs#3826
1 parent 4eb1635 commit aad9d38

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* `Tween.init` and `Tween.play` have been rewritten so they are not run multiple times when a Tween is paused before playback, or is part of a Timeline. This didn't cause any problems previously, but it was a redundant duplication of calls.
2121
* `Tween.onLoop` will now be invoked _after_ the `loopDelay` has expired, if any was set.
2222
* `Tween.onRepeat` will now be invoked _after_ the `repeatDelay` has expired, if any was set.
23+
* `easeParams` would be ignored for tweens that _didn't_ use a string for the ease function name. Fix #3826 (thanks @SBCGames)
24+
* You can now specify `easeParams` for any custom easing function you wish to use. Fix #3826 (thanks @SBCGames)
2325

2426
### New Features
2527

src/tweens/builders/GetEaseFunction.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,43 @@ var EaseMap = require('../../math/easing/EaseMap');
1919
*/
2020
var GetEaseFunction = function (ease, easeParams)
2121
{
22+
// Default ease function
23+
var easeFunction = EaseMap.Power0;
24+
25+
// Prepare ease function
2226
if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease))
2327
{
24-
if (easeParams)
25-
{
26-
var cloneParams = easeParams.slice(0);
27-
28-
cloneParams.unshift(0);
29-
30-
return function (v)
31-
{
32-
cloneParams[0] = v;
33-
34-
return EaseMap[ease].apply(this, cloneParams);
35-
};
36-
}
37-
else
38-
{
39-
// String based look-up
40-
return EaseMap[ease];
41-
}
28+
// String based look-up
29+
easeFunction = EaseMap[ease];
4230
}
4331
else if (typeof ease === 'function')
4432
{
4533
// Custom function
46-
return ease;
34+
easeFunction = ease;
4735
}
4836
else if (Array.isArray(ease) && ease.length === 4)
4937
{
5038
// Bezier function (TODO)
5139
}
5240

53-
return EaseMap.Power0;
41+
// No custom ease parameters?
42+
if (!easeParams)
43+
{
44+
// Return ease function
45+
return easeFunction;
46+
}
47+
48+
var cloneParams = easeParams.slice(0);
49+
50+
cloneParams.unshift(0);
51+
52+
// Return ease function with custom ease parameters
53+
return function (v)
54+
{
55+
cloneParams[0] = v;
56+
57+
return easeFunction.apply(this, cloneParams);
58+
};
5459
};
5560

5661
module.exports = GetEaseFunction;

0 commit comments

Comments
 (0)