cookbook: Use new API to reverse timeline
clutter_timeline_set_reverse() can be used to automatically reverse a timeline's direction each time it completes, so use that in looping animation recipe and examples.
This commit is contained in:
parent
4f17bf3bcc
commit
50849ac1fd
@ -2372,7 +2372,7 @@ clutter_actor_animate_with_timeline (actor,
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</informalexample>
|
</informalexample>
|
||||||
|
|
||||||
<para>One further technique is to swop the timeline's
|
<para>One further technique is to repeatedly reverse the timeline's
|
||||||
direction to create a "closed loop" animation (one which returns
|
direction to create a "closed loop" animation (one which returns
|
||||||
to its origin at the end of each iteration). See
|
to its origin at the end of each iteration). See
|
||||||
<link linkend="animations-looping-discussion-closed-loop">this
|
<link linkend="animations-looping-discussion-closed-loop">this
|
||||||
@ -2655,12 +2655,23 @@ timeline_completed_cb (ClutterTimeline *timeline,
|
|||||||
animations, one the inverse of the other, and chaining them together.</para>
|
animations, one the inverse of the other, and chaining them together.</para>
|
||||||
|
|
||||||
<para>However, a simpler solution is to run forward through the timeline
|
<para>However, a simpler solution is to run forward through the timeline
|
||||||
once; then invert its direction when the end of timeline is reached.
|
once, and have the timeline invert itself when its end is reached.
|
||||||
The animation continues, but in reverse. Once the backward iteration
|
The animation then continues, but in reverse. Once the backward iteration
|
||||||
completes, set the timeline to run forward again. Keep changing the
|
completes, the timeline sets itself to run forward again, etc.</para>
|
||||||
timeline's direction each time it completes. This
|
|
||||||
is the approach used in <link linkend="animations-looping-example-1">the
|
<para>To make a timeline reverse its direction each time it
|
||||||
example</link>, which results in a smooth, repeated right to left,
|
completes, use the <function>clutter_timeline_set_reverse()</function>
|
||||||
|
function:</para>
|
||||||
|
|
||||||
|
<informalexample>
|
||||||
|
<programlisting>
|
||||||
|
clutter_timeline_set_reverse (timeline, TRUE);
|
||||||
|
</programlisting>
|
||||||
|
</informalexample>
|
||||||
|
|
||||||
|
<para>This is the approach used in
|
||||||
|
<link linkend="animations-looping-example-1">the example</link>,
|
||||||
|
which results in a smooth, repeated right to left,
|
||||||
left to right motion.</para>
|
left to right motion.</para>
|
||||||
|
|
||||||
<para>See <link linkend="animations-inversion">this
|
<para>See <link linkend="animations-inversion">this
|
||||||
|
@ -10,20 +10,6 @@ typedef struct
|
|||||||
ClutterTimeline *timeline;
|
ClutterTimeline *timeline;
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
static void
|
|
||||||
invert_timeline_cb (ClutterTimeline *timeline,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
ClutterTimelineDirection direction = clutter_timeline_get_direction (timeline);
|
|
||||||
|
|
||||||
if (direction == CLUTTER_TIMELINE_FORWARD)
|
|
||||||
direction = CLUTTER_TIMELINE_BACKWARD;
|
|
||||||
else
|
|
||||||
direction = CLUTTER_TIMELINE_FORWARD;
|
|
||||||
|
|
||||||
clutter_timeline_set_direction (timeline, direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
key_pressed_cb (ClutterActor *actor,
|
key_pressed_cb (ClutterActor *actor,
|
||||||
ClutterEvent *event,
|
ClutterEvent *event,
|
||||||
@ -63,21 +49,13 @@ main (int argc,
|
|||||||
|
|
||||||
state->timeline = clutter_timeline_new (1000);
|
state->timeline = clutter_timeline_new (1000);
|
||||||
clutter_timeline_set_loop (state->timeline, TRUE);
|
clutter_timeline_set_loop (state->timeline, TRUE);
|
||||||
|
clutter_timeline_set_reverse (state->timeline, TRUE);
|
||||||
|
|
||||||
g_signal_connect (stage,
|
g_signal_connect (stage,
|
||||||
"key-press-event",
|
"key-press-event",
|
||||||
G_CALLBACK (key_pressed_cb),
|
G_CALLBACK (key_pressed_cb),
|
||||||
state);
|
state);
|
||||||
|
|
||||||
/* the animation will not emit a "completed" signal,
|
|
||||||
* as it is set to loop; but the timeline emits "completed"
|
|
||||||
* at the end of each iteration of the loop
|
|
||||||
*/
|
|
||||||
g_signal_connect (state->timeline,
|
|
||||||
"completed",
|
|
||||||
G_CALLBACK (invert_timeline_cb),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), state->actor);
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), state->actor);
|
||||||
|
|
||||||
clutter_actor_show (stage);
|
clutter_actor_show (stage);
|
||||||
|
Loading…
Reference in New Issue
Block a user