class flaxen.common.Easing
Available on all platforms
A set of easing functions for tweening.
Each EasingFunction
takes a time value from 0-1, and returns an eased time value.
Some easing functions can return outside of the 0-1, say, to create an overshot/backup effect.
These methods don't actually do any tweening, they only apply easing to a 0-1 T value. You might fight other easing systems calculating in start/change values and a 0-duration time, but I think this "less pithy" way of doing easing functions puts the work of calculating the effect of an easing function on a tween into the Tween class itself, where t should be.
You can customize some of these easing functions using the customXxx methods.
There are helper getXxx methods to assist you in creating your own easing functions.
Although not a perfect match, you can use GreenSock's ease visualizer to get a better idea of how these easing functions affect movement:
https://greensock.com/roughease
Class Fields
static function backIn(t:Float):Float
Back in - slow to back up, and then fast to target.
The backup amount is 10%. To customize this, create your
own easing function by calling getBack
.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function backInOut(t:Float):Float
Back in/out - back up, overshoot target, and ease back.
For back out/in, make your own easing function with
getSerial(t, backOut, backIn)
.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function backOut(t:Float):Float
Back out - slow to overshoot and then fast to target.
The overshoot amount is 10%. To customize this, create your
own easing function by calling the inverse of getBack
.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function bounceIn(t:Float):Float
Bounce in - four bounces, each dropping to 0 and gaining height.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function bounceInOut(t:Float):Float
Bounce in/out - bounce in to 0.5, then bounce out to 1.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function bounceOut(t:Float):Float
Bounce in - four bounces, each flying to 1 and losing height.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function circIn(t:Float):Float
Circular in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function circInOut(t:Float):Float
Circular easing in/out - acceleration until halfway, then deceleration.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function circOut(t:Float):Float
Circular out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function cubicIn(t:Float):Float
Cubic in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function cubicInOut(t:Float):Float
Cubic easing in/out - acceleration until halfway, then deceleration
For cubicOutIn, call poly(OutIn, 3).
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function cubicOut(t:Float):Float
Cubic out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function customJitter(func:EasingFunction, ?amount:Float = 0.05):EasingFunction
Applies jitter to another easing function.
func | The easing function to jitter |
amount | The maximal amount of jitter; e.g., 0.1 means the variation is +/- 0.05. |
returns | An easing function |
static function customParallel(first:EasingFunction, second:EasingFunction):EasingFunction
Runs two easing functions in parallel.
Supplies the result of the first easing function to the second easing function.
first | The first easing function |
second | The second easing function |
returns | An easing function |
static function customPoly(dir:EaseDirection, ?exp:Int = 2, ?midpoint:Float = 0.5):EasingFunction
Custom polynomial easing.
Supports any exponent. Supports In, Out, InOut, and OutIn.
dir | Which direction to ease, see |
exp | The exponent for the polynomial; 2=quad, 3=cubic, 4=quartic, 5=quintic, etc. |
midpoint | When doing InOut or OutIn, uses this to determine where to stop one ease and start the other |
returns | An easing function |
static function customRough(func:EasingFunction, ?amount:Float = 0.1, ?points:Int = 10):EasingFunction
Applies a roughness to another easing function.
You select the maximal amount of roughness, and the number of points to apply roughness. The roughness is interpolated between the points, so more points makes more perturbations.
func | The easing function to roughen |
amount | The maximal amount of roughness; e.g., 0.1 means the variation is +/- 0.05. |
points | The number of points where a new roughness peak is introduced |
returns | An easing function |
static function customSerial(first:EasingFunction, second:EasingFunction, ?midpoint:Float = 0.5):EasingFunction
Runs two easing functions in serial.
Creates an easing function where the first ease occurs to the left of the midpoint, and the second ease to the right of the midpoint. Each ease is scaled to fit within its range.
first | The first easing function, to operate from 0 to midpoint |
second | The second easing function, to operate from midpoint to 1 |
midpoint | The point from 0-1 where the first easing turns to the second easing. |
returns | An easing function |
static function expoIn(t:Float):Float
Exponential in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function expoInOut(t:Float):Float
Exponential in/out - accelerating until halfway, then decelerating.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function expoOut(t:Float):Float
Exponential out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function getBack(t:Float, ?amount:Float = 1.70158):Float
Calculates the back in value. See backIn
.
Returns an eased T that backs below 0 by amount
up before shooting to 1.
t | A time value, usually from 0 to 1 |
amount | The amount to back up; the defaults corresponds to about a 10% backup |
returns | A time value, usually from 0 to 1 |
static function getInverse(t:Float, func:EasingFunction):Float
Returns the inverse value for an easing function, this applies the effect at the opposite sides of the timeline.
Use this in an easing function definition.
t | A time value, usually from 0 to 1 |
func | An easing function to return the inverse of |
returns | A time value, usually from 0 to 1 |
static function getJitter(t:Float, jitterAmount:Float):Float
Adds an amount of continuous jitter to a T value.
Use this in an easing function definition.
t | A time value, usually from 0 to 1 |
first | The first easing function, to operate from 0 to midpoint |
second | The second easing function, to operate from midpoint to 1 |
returns | A time value, usually from 0 to 1 |
static function getParallel(t:Float, first:EasingFunction, second:EasingFunction):Float
Combines two easing functions in parallel. The result of the first function is passed to the second function, and that result is returned.
Use this in an easing function definition.
t | A time value, usually from 0 to 1 |
first | The first easing function, to operate from 0 to midpoint |
second | The second easing function, to operate from midpoint to 1 |
returns | A time value, usually from 0 to 1 |
static function getSerial(t:Float, first:EasingFunction, second:EasingFunction, ?midpoint:Float = 0.5):Float
Combines two easing functions, serially.
Returns a value where if t < midpoint, the value is eased and scaled according to the first easing function, otherwise it is eased and scaled according to the second easing function.
Use this in an easing function definition.
- CONSIDER: Separate the time midpoint from the spatial midpoint, right now they mean the same thing
t | A time value, usually from 0 to 1 |
first | The first easing function, to operate from 0 to midpoint |
second | The second easing function, to operate from midpoint to 1 |
midpoint | The point from 0-1 where the first easing turns to the second easing. |
returns | A time value, usually from 0 to 1 |
static function linear(t:Float):Float
Simple linear easing - i.e, no easing.
This works like an easing function loopback, just passing back the supplied value.
This method could have just as well been called none
.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quadIn(t:Float):Float
Quadratic in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quadInOut(t:Float):Float
Quadratic easing in/out - acceleration until halfway, then deceleration.
For quadOutIn, call poly(OutIn, 2).
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quadOut(t:Float):Float
Quadratic out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quartIn(t:Float):Float
Quartic in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quartInOut(t:Float):Float
Quartic easing in/out - acceleration until halfway, then deceleration.
For quartOutIn, call poly(OutIn, 4).
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quartOut(t:Float):Float
Quartic easing out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quintIn(t:Float):Float
Quintic in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quintInOut(t:Float):Float
Quintic easing in/out - acceleration until halfway, then deceleration.
For quintOutIn, call poly(OutIn, 3).
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function quintOut(t:Float):Float
Quintic out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function random(t:Float):Float
Totally random stuttering about the timeline. Totally. Random. The effect may look different depending on the frame rate.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function sineIn(t:Float):Float
Sinusoidal in - accelerating from zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function sineInOut(t:Float):Float
Sinusoidal in/out - accelerating until halfway, then decelerating.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |
static function sineOut(t:Float):Float
Sinusoidal out - decelerating to zero velocity.
t | A time value, usually from 0 to 1 |
returns | A time value, usually from 0 to 1 |