Clutter Learning (10): Multiple timeline -- clutterscore

Source: Internet
Author: User

In the last study, we learned ClutterTimeline. We added multiple ClutterTimeline through ClutterScore, which can be triggered at the same time or in sequence. We will discuss them here. Source of learning materials:

Grouping Timelines in Score

,

Example

.

Usage: first create a ClutterScore, and then add each timeline through clutter_score_append. If the second parameter of this function is NULL, it indicates that it is executed as the first timeline, and multiple first timeline can be executed at the same time. The second parameter can also be a timeline, indicates that the timeline is executed in sequence after a certain timeline. The two methods can be expressed as parallel and serial respectively. Suppose we have two timeline intervals: t1 and t2. They both set the trigger for maker-reached, respectively, a1 and a2, they also have a new-frame refresh trigger.

Is serial, that is, the description of sequential execution. The cycle time is the sum of the time used as the timeline, that is, t1 + t2 + t3 + ...... + Tn, we need to note that the new-frame time is valid. A timeline screen flushing is triggered only within the effective time. The dynamic effect we set in the new-frame of t1 will be paused at the beginning of T2. the execution will continue when T1.

The figure on the right shows the example of parallel triggering. The cycle time is MAX (t1, t2, t3 ,......, Tn). If you use new-frame, you must note that it is only within the effective time range of timeline. This must be emphasized. Through the combination of parallel and serial methods, we can construct the timeline mode that meets our needs. However, according to the programming philosophy, we should minimize replication and strive to be concise. Adding complexity to render your programming capabilities is not a matter of ignorance.

The following is an example. We have set two timelines, namely timeline1 and timeliness2. Their new-frame triggers are rotating and moving a png Image respectively. At the same time, the timestamp is printed out through the mark-reached trigger to track their execution methods.

# Include <clutter/clutter. h>

# Include <stdlib. h>

# Include <time. h>

Long offset = 0;

Long get_time (){

Return time (0)-offset;

}

/* This is the new-frame trigger of timline1 */

Void on_timeline_new_frame1 (ClutterTimeline * timeline, gint frame_num, gpointer data ){

Static float step = 0;

Step + = 1.0;

If (step >=360)

Step = 0;

Clutter_actor_set_rotation (ClutterActor *) data, CLUTTER_X_AXIS, step, 0, 0 );

}

/* This is the new-frame trigger of timline2 */

Void on_timeline_new_frame2 (ClutterTimeline * timeline, gint frame_num, gpointer data ){

Clutter_actor_move_by (ClutterActor *) data, 0.4, 0 );

}

/* This is the trigger of mark-reached of timeline1 and timeline2 */

Void on_timeline_marker_reached (ClutterTimeline * timeline,

Gchar * marker_name, gint msecs_num, gpointer data ){

Printf ("% 03ld marker % s reached: msec-num = % d/n", get_time (), marker_name, msecs_num );

}

Int main (int argc, char * argv []) {

ClutterColor stage_color = {0x00,0x00,0x00, 0xff };

Clutter_init (& argc, & argv );

/* Clutter stage and rect */

ClutterActor * stage = clutter_stage_get_default ();

Clutter_actor_set_size (stage, 800,300 );

Clutter_stage_set_color (CLUTTER_STAGE (stage), & stage_color );

ClutterActor * rect = clutter_texture_new_from_file ("20.png", NULL );
If (rect = NULL ){
Printf ("Can't locate the texture file: paipng/ n ");
Return-1;
}
Clutter_actor_set_position (rect, 50,150 );

Clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect );

Clutter_actor_show (rect );

Clutter_actor_show (stage );

/* Clutter Score study */

ClutterScore * score =Clutter_score_new

();

Clutter_score_set_loop

(Score, TRUE );

ClutterTimeline * timeline1 = clutter_timeline_new (5000 );

Clutter_timeline_add_marker_at_time (timeline1, "my-mark", 1000 );

G_signal_connect (timeline1, "new-frame", G_CALLBACK (on_timeline_new_frame1), rect );

G_signal_connect (timeline1, "marker-reached", G_CALLBACK (on_timeline_marker_reached), NULL );

Clutter_score_append (Score, NULL, timeline1

);

ClutterTimeline * timeline2 = clutter_timeline_new (6000 );

Clutter_timeline_add_marker_at_time (timeline2, "timeline2", 2000 );

G_signal_connect (timeline2, "new-frame", G_CALLBACK (on_timeline_new_frame2), rect );

G_signal_connect (timeline2, "marker-reached", G_CALLBACK (on_timeline_marker_reached), NULL );

Clutter_score_append (Score, NULL, timeline2

);

/* Parallel test */

// Clutter_score_append (Score, timeline1, timeline2

);

/* Serial test */

Offset = time (0 );

Clutter_score_start

(Score );

Clutter_main ();

G_object_unref (timeline1 );

G_object_unref (timeline2 );

G_object_unref (score );

Return EXIT_SUCCESS;

}

Related links:



My Clutter blog

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.