Let's get everything moving

We have introduced transitions in Chapter 3, Building Our First Game – Breakout, and briefly touched base with it. Let's go into more detail.

The transition library allows you to create animations with only a single line of code by allowing you to tween one or more properties of a display object. We have discussed the basics of transitions back in Chapter 3, Building Our First Game – Breakout.

This can be done through the transition.to method, which takes a display object and a table that contains the control parameters. The control parameters specify the duration of the animation and the final values of properties for the display object. The intermediate values for a property are determined by an optional easing function, which is also specified as a control parameter.

The transition.to() method animates a display object's properties over time, using the "easing" algorithm.

The syntax is handle = transition.to( target, params ).

The return function is an object. The parameters are as follows:

The easing library is a collection of interpolation functions used by the transition library. One example is opening a drawer. The first movement at first is fast and then a slow precise movement before it stops. The following are some easing examples:

You can create your own easing function to interpolate between a start and a final value. The arguments of the function are defined as follows:

For example: