## Creating Animations with Clutter

### Matthew Allum

`<mallum@openedhand.com>`

With Clutter using hardware accelration for graphics rendering, complex and fast animations are possible. This chapter describes basic techniques and the utilities Clutter provides in aiding animation creation.

## Basic Animations

The most basic way to create animations with Clutter is via the use of g_timeout_add(). This enables a callback function to be called at a defined interval. The callback function can then modify actors visual properties as to produce an animation.

Example 8.

Simple Rotation...

    struct RotationClosure {
      ClutterActor *actor;
      ClutterFixed final_angle;
      ClutterFixed current_angle;
    };

    static gboolean
    rotate_actor (gpointer data)
    {
      RotationClosure *clos = data;

      clutter_actor_set_rotationx (clos->actor, clos->current_angle, 0, 0, 0);

      clos->current_angle += CFX_ONE;

      if (clos->current_angle == clos->final_angle)
        return FALSE;

      return TRUE;
    }

    ...
      RotationClosure clos = { NULL, }

      clos.actor = an_actor;
      clos.final_angle = CLUTTER_FLOAT_TO_FIXED (360.0);
      clos.current_angle = 0;

      g_timeout_add (1000 / 360, /* fps to interval in milliseconds */
                     rotate_actor,
                     &clos);

### Priorities

%G_PRIORITY_DEFAULT should always be used as the timeouts priority (in case of g_timeout_add_full()) as not to intefere with Clutter's scheduling of repaints and input event handling.