| 1 |
<?xml version="1.0"?> |
| 2 |
<!DOCTYPE chapter PUBLIC |
| 3 |
"-//OASIS//DTD DocBook XML V4.3//EN" |
| 4 |
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ |
| 5 |
]> |
| 6 |
<chapter id="migrating-ClutterBehaviour"> |
| 7 |
|
| 8 |
<chapterinfo> |
| 9 |
<author> |
| 10 |
<firstname>Emmanuele</firstname> |
| 11 |
<surname>Bassi</surname> |
| 12 |
<affiliation> |
| 13 |
<address> |
| 14 |
<email>[email protected]</email> |
| 15 |
</address> |
| 16 |
</affiliation> |
| 17 |
</author> |
| 18 |
</chapterinfo> |
| 19 |
|
| 20 |
<title>Migrating from ClutterBehaviour</title> |
| 21 |
|
| 22 |
<para>The #ClutterBehaviour class and its sub-classes have been deprecated |
| 23 |
since Clutter 1.6. The animation framework provided by #ClutterAnimation, |
| 24 |
#ClutterAnimator and #ClutterState fully replaces all functionality from the |
| 25 |
#ClutterBehaviour classes.</para> |
| 26 |
|
| 27 |
<para>Generally, animations using #ClutterBehaviour sub-classes can be |
| 28 |
effectively re-implemented just by using #ClutterActor properties.</para> |
| 29 |
|
| 30 |
<para>Here is an example of an animation using a |
| 31 |
#ClutterBehaviourOpacity instance:</para> |
| 32 |
|
| 33 |
<informalexample> |
| 34 |
<programlisting> |
| 35 |
ClutterTimeline *timeline = clutter_timeline_new (250); |
| 36 |
ClutterAlpha *alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); |
| 37 |
ClutterBehaviour *behaviour = clutter_behaviour_opacity_new (alpha, 255, 0); |
| 38 |
|
| 39 |
clutter_behaviour_apply (behaviour, some_actor); |
| 40 |
|
| 41 |
clutter_timeline_start (timeline); |
| 42 |
</programlisting> |
| 43 |
</informalexample> |
| 44 |
|
| 45 |
<para>The same effect can be achieved by using clutter_actor_animate() and |
| 46 |
the #ClutterActor:opacity property:</para> |
| 47 |
|
| 48 |
<informalexample> |
| 49 |
<programlisting> |
| 50 |
clutter_actor_set_opacity (some_actor, 255); |
| 51 |
clutter_actor_animate (some_actor, CLUTTER_LINEAR, 250, |
| 52 |
"opacity", 0, |
| 53 |
NULL); |
| 54 |
</programlisting> |
| 55 |
</informalexample> |
| 56 |
|
| 57 |
<para>#ClutterBehaviour<!-- -->s used for continuous animations with looping |
| 58 |
timelines can still be effectively replaced by looping animations; for |
| 59 |
instance, the following example of a "pulsating" actor using |
| 60 |
#ClutterBehaviourScale:</para> |
| 61 |
|
| 62 |
<informalexample> |
| 63 |
<programlisting> |
| 64 |
static void |
| 65 |
reverse_timeline (ClutterTimeline *timeline) |
| 66 |
{ |
| 67 |
ClutterTimelineDirection dir = clutter_timeline_get_direction (timeline); |
| 68 |
|
| 69 |
if (dir == CLUTTER_TIMELINE_FORWARD) |
| 70 |
dir = CLUTTER_TIMELINE_BACKWARD; |
| 71 |
else |
| 72 |
dir = CLUTTER_TIMELINE_FORWARD; |
| 73 |
|
| 74 |
clutter_timeline_set_direction (timeline, dir); |
| 75 |
} |
| 76 |
|
| 77 |
ClutterTimeline *timeline = clutter_timeline_new (500); |
| 78 |
ClutterAlpha *alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); |
| 79 |
ClutterBehaviour *behaviour; |
| 80 |
|
| 81 |
g_object_set (some_actor, "scale-gravity", CLUTTER_GRAVITY_CENTER, NULL); |
| 82 |
behaviour = clutter_behaviour_scale_new (alpha, |
| 83 |
1.0, 2.0, |
| 84 |
1.0, 2.0); |
| 85 |
clutter_behaviour_apply (behaviour, some_actor); |
| 86 |
|
| 87 |
g_signal_connect (timeline, |
| 88 |
"completed", G_CALLBACK (reverse_timeline), |
| 89 |
NULL); |
| 90 |
|
| 91 |
clutter_timeline_set_loop (timeline); |
| 92 |
clutter_timeline_start (timeline); |
| 93 |
</programlisting> |
| 94 |
</informalexample> |
| 95 |
|
| 96 |
<para>The same effect can be achieved using a #ClutterAnimation:</para> |
| 97 |
|
| 98 |
<informalexample> |
| 99 |
<programlisting> |
| 100 |
ClutterAnimation *animation = |
| 101 |
clutter_actor_animate (some_actor, CLUTTER_LINEAR, 500, |
| 102 |
"scale-x", 2.0, |
| 103 |
"scale-y", 2.0, |
| 104 |
"fixed::scale-gravity", CLUTTER_GRAVITY_CENTER, |
| 105 |
NULL); |
| 106 |
|
| 107 |
ClutterTimeline *timeline = clutter_animation_get_timeline (animation); |
| 108 |
clutter_timeline_set_repeat_count (timeline, -1); |
| 109 |
clutter_timeline_set_auto_reverse (timeline, TRUE); |
| 110 |
</programlisting> |
| 111 |
</informalexample> |
| 112 |
|
| 113 |
<para>#ClutterBehaviour sub-classes can be applied to multiple actors, in |
| 114 |
order to share the duration and the easing mode. It is possible to use the |
| 115 |
same underlying #ClutterTimeline and #ClutterAlpha instances with |
| 116 |
#ClutterAnimation to achieve the same effect. Complex animations, spanning |
| 117 |
multiple actors, should use the #ClutterAnimator and #ClutterState classes |
| 118 |
instead.</para> |
| 119 |
|
| 120 |
</chapter> |