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 Clutter::Timeline's signal_new_frame() signal allows you to set actor properties for each frame, Cluttermm 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, Clutter::BehaviourPath moves the actor along a specified path, calculating the position on the path once per frame by calling a supplied alpha_func slot. The Clutter::Alpha object is constructed with this slot and a Clutter::Timeline 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_func slot 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_func, 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 containers, behaviours maintain a reference to the supplied Clutter::Alpha object. For this reason it is not necessary to keep around a reference to the alpha object yourself. However, you should clear the smart pointers to the behaviours when you are finished with them.

Clutter::BehaviourPath class reference

Clutter::Alpha class reference

The following standard behaviours are available in Cluttermm: