Chapter 8. Behaviours

Table of Contents

Using Behaviours

The Effects API is simple but you will often need to use behaviours directly to have more control.

Although the ClutterTimeline's new-frame signal allows you to set actor properties for each frame, Clutter also provides Behaviours which can change specific properties of one specific actor over time, using a simple numeric calculation. However, unlike the simplified Effects API, using behaviours directly allows you to combine them to control multiple actors simultaneously and allows you to change the parameters of the behaviours while the timeline is running.

For instance, ClutterBehaviourPath moves the actor along a specified path, calculating the position on the path once per frame by calling a supplied alpha callback. The ClutterAlpha object is constructed with this callback and a ClutterTimeline which tells it when a new frame needs a new value to be calculated.

Figure 8.1. Effects of alpha functions on a path.

Effects of alpha functions on a path.

Your alpha 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(). Several built-in callbacks, such as CLUTTER_ALPHA_SINE, allow you to easily specify natural movement.

If the behaviour's timeline is started and not stopped then the end point of the behaviour will always be reached and it will end there unless the timeline is set to loop. For instance, an actor will move along a path until it has reached the end, taking as much time as specified by the timeline's number of frames and frames per second.

Like actors, ClutterAlpha has a "floating references" so you don't need to unref it if you have added it to a behaviour. However, the behaviours do not have a floating reference, so you should unref them when you are finished with them. You might do this at the same time as you unref the timeline, for instance in a signal handler for the timeline's completed signal.

ClutterBehaviour Reference

ClutterAlpha Reference

The following standard behaviours are available in Clutter: