Chapter 7. Effects

Table of Contents

Using Effects

Clutter provides several effects functions that can be used together with a timeline to change the properties of a single actor over time, using a simple numeric calculation. In many cases this is an easier way to implement animation. For instance, clutter_effect_fade() gradually changes the opacity of an actor or clutter_effect_rotate() gradually changes the rotation of an actor, calculating the opacity or rotation by calling the supplied alpha callback.

To use a clutter effect, you should first create a ClutterEffectTemplate, specifying your timeline object and a ClutterAlphaFunc callback. This callback will need to call clutter_alpha_get_timeline() so it can return a value based on the timeline's current frame number and total number of frames, using clutter_timeline_get_current_frame() and clutter_timeline_get_n_frames(). The result should be between 0 and CLUTTER_ALPHA_MAX, with the meaning of the result depending on the effect used. For instance, CLUTTER_ALPHA_MAX would be 100% opacity when using clutter_effect_fade(). Several built-in callbacks, such as CLUTTER_ALPHA_SINE, allow you to easily specify natural movement.

Figure 7.1. Graphic representation of some alpha functions.

Graphic representation of some alpha functions.

You should then provide this ClutterEffectTemplate to one of the clutter_effect functions, along with the actor and any extra parameters required by that function. Remember to unref the effect template after providing it to the effect function (which will take a reference). Unlike actors, these do not have "floating references".

To make it easier to use different timelines with different effects, you can use clutter_effect_template_set_timeline_clone() to cause the effect to clone (copy instead of just referencing) the timeline, allowing you to change the original timeline and supply it to a second effect, without influencing the first effect.

The effects API is actually a simplified API that wraps the ClutterBehaviour objects. However, the effect functions can only control one actor at a time and do not allow you to change the effects while the timeline is running. To do this you can use the behaviours directly, as described in the Behaviours section.

Reference