Emmanuele Bassi > Clutter > xs/ClutterAnimation.xs

Download:
Clutter-1.002.tar.gz

Annotate this POD

CPAN RT

New  2
Open  2
View Bugs
Report a bug
Source  

SYNOPSIS ^

    my $animation = Clutter::Animation->new();

    # 500 milliseconds of duration
    $animation->set_duration(500);

    # cubic easing mode
    $animation->set_mode('ease-out-cubic');

    # set the object we want to animate
    $animation->set_object($texture);

    # bind the properties we want to animate on the object; bind()
    # calls can be chained up to
    $animation->bind('scale-x', 2.0)
              ->bind('scale-y', 2.0)
              ->bind('opacity', 255);

    # start the animation
    $animation->get_timeline()->start();

    # set the object as reactive when the animation ends
    $animation->signal_connect(completed => sub {
        $animation->get_object()->set_reactive(TRUE);
    })

DESCRIPTION ^

Clutter::Animation is an class providing simple, implicit animations for Glib::Object instances.

Clutter::Animation instances will bind one or more object properties belonging to a Glib::Object to a Clutter::Interval, and will then use a Clutter::Alpha to interpolate the property between the initial and final values of the interval.

The duration of the animation is set using Clutter::Animation::set_duration(). The easing mode of the animation is set using Clutter::Animation::set_mode().

Controlling the Animation

If you want to control the animation you should retrieve the Clutter::Timeline using Clutter::Animation::get_timeline() and then use Clutter::Timeline methods like Clutter::Timeline::start(), Clutter::Timeline::pause() or Clutter::Timeline::stop().

A Clutter::Animation will emit the Clutter::Animation::completed signal when the Clutter::Timeline used by the animation is completed; unlike Clutter::Timeline, though, the Clutter::Animation::completed will not be emitted if Clutter::Animation:loop is set to %TRUE - that is, a looping animation never completes.

If your animation depends on user control you can force its completion using Clutter::Animation::completed().

If the Glib::Object instance bound to a Clutter::Animation implements the Clutter::Animatable interface it is possible for that instance to control the way the initial and final states are interpolated.

Changing the Animation

The initial and final value of a property bound to the Animation are controlled by a Clutter::Interval instance. You can retrieve the Interval instance and change the values, or you can change the Interval instance itself:

    # increase the scaling factor
    $animation->get_interval('scale-x')->set_final_value(2.5);
    $animation->get_interval('scale-y')->set_final_value(2.5);

    # change the opacity interval
    $cur_value = $animation->get_object()->get_opacity();
    $interval = Clutter::Interval->new('Glib::Uchar');
    $interval->set_interval($cur_value, 128);
    $animation->update_interval('opacity', $interval);

Differences between Animation and Behaviour

Clutter::Animation is distinguished from Clutter::Behaviour because the former can only control Glib::Object properties of a single Glib::Object instance, while the latter can control multiple properties using accessor functions inside the Clutter::Behaviour::ALPHA_NOTIFY virtual function, and can control multiple Clutter::Actors at the same time.

Convenience API

For convenience, it is possible to use the Clutter::Actor::animate() method which will take care of setting up and tearing down a Clutter::Animation instance and animate an actor between its current state and the specified final state:

    $texture->animate(
        'ease-out-cubic', 500,
        scale_x => 2.0,
        scale_y => 2.0,
        opacity => 255
    )->signal_connect(completed => sub { $texture->set_reactive(TRUE) })

The example above reproduces the same animation as the one in the Synopsis.

The Clutter::Animation instance created by Clutter::Actor::animate() is managed by the animate() method itself and it is guaranteed to be valid for as long as the animation is running; once the animation emits the completed signal, the animation will still be valid from within handlers connected to that signal, until the default signal handler is executed.

SEE ALSO ^

Clutter::Timeline, Clutter::Alpha, Clutter::Behaviour, Clutter::Interval, Clutter::Actor.

An implicit Clutter::Interval will be created which will use:

the type of the property
the current value as the initial value
the passed final value as the final value

This method will croak if animation does not have an object set.