Skip to content

Easings

Michael edited this page Apr 16, 2022 · 1 revision

Sometimes you want to use fancy easing curves for various things in games. In the days of old this would have been a lot of math, and in modern times you'd probably use animation curves for it. I wrote a bit of code to act as a nice interface for animation curves.

Relevant Links

ease(val1, val2, f, curve_type)

This is the main function you'll want to use. It's basically a mirror of lerp where you specify the curve type.

Returns: number

Parameter Type Description
val1 real The starting number you want to interpolate from.
val2 real The final number you want to interpolate to.
f real The amount you want to interpolate by (usually a number between 0 and 1).
curve_type Easings or string The type of easing curve you want to use.

If you've ever used lerp before, which most of you probably have, the first three arguments are exactly the same.

curve_type can be either a member of the Easings enum or a string containing the name of the curve. See the chart below for reference.

easing_get(curve_type, f)

Returns: number

Parameter Type Description
curve_type Easings or string The type of easing curve you want to use.
f real The amount you want to interpolate by (usually a number between 0 and 1).

Like the above, but this function returns a value between (approximately) 0 and 1, without any min or max value.

global.animation_tween_names

If you want to attach nice, readable names to the easing curves (perhaps you want to show it to the user or something) there's a little global array with text strings corresponding to the members of the Easings enum.

Easing chart

String name Enum name Curve name
Linear Easings.LINEAR "linear"
Quadratic In Easings.QUAD_I "quad_i"
Quadratic Out Easings.QUAD_O "quad_o"
Quadratic In/Out Easings.QUAD_IO "quad_io"
Cubic In Easings.CUBE_I "cubic_i"
Cubic Out Easings.CUBE_O "cubic_o"
Cubic In/Out Easings.CUBE_IO "cubic_io"
Quartic In Easings.QUART_I "quart_i"
Quartic Out Easings.QUART_O "quart_o"
Quartic In/Out Easings.QUART_IO "quart_io"
Exponential In Easings.EXP_I "exp_i"
Exponential Out Easings.EXP_O "exp_o"
Exponential In/Out Easings.EXP_IO "exp_io"
Circular In Easings.CIRC_I "circ_i"
Circular Out Easings.CIRC_O "circ_o"
Circular In/Out Easings.CIRC_IO "circ_io"
Back In Easings.BACK_I "back_i"
Back Out Easings.BACK_O "back_o"
There and Back Again Easings.BACK_IO "back_io"
Elastic In Easings.ELASTIC_I "elastic_i"
Elastic Out Easings.ELASTIC_O "elastic_o"
Elastic In/Out Easings.ELASTIC_IO "elastic_io"
Bounce In Easings.BOUNCE_I "bounce_i"
Bounce Out Easings.BOUNCE_O "bounce_o"
Bounce In/Out Easings.BOUNCE_IO "bounce_io"
Fast to Slow Easings.FAST_TO_SLOW "fast_to_slow"
Mid to Slow Easings.MID_TO_SLOW "mid_slow"
Clone this wiki locally