like the documentation for ClutterActor.animate() says:
Calling this function on an actor that is already being animated will cause the current animation to change with the new final values, the new easing mode and the new duration https://developer.gnome.org/clutter/stable/clutter-Implicit-Animations.html#clutter-actor-animate
which means that the following code:
actor.animatev(Clutter.AnimationMode.LINEAR, 1000, ["x"], [280])
actor.animatev(Clutter.AnimationMode.LINEAR, 1000, ["x"], [20])
is exactly equivalent to:
actor.animatev(Clutter.AnimationMode.LINEAR, 1000, ["x"], [20])
which is what you're seeing.
if you want to chain up two animations you have to connect to the completed
signal of ClutterAnimation
, using the connect_after
function, so that Clutter can create a new animation:
def moveLeft (animation, actor):
actor.animatev(Clutter.AnimationMode.LINEAR, 1000, ["x"], [20])
actor.animatev(Clutter.AnimationMode.LINEAR, 1000, ["x"], [280]).connect_after('completed', moveLeft)
I'd like to point out that animatev()
and ClutterAnimation
are deprecated; they can be replaced by using an explicit Clutter.KeyframeTransition
or an implicit transition, for instance:
from gi.repository import Clutter
Clutter.init(None)
stage = Clutter.Stage()
stage.connect('destroy', lambda x: Clutter.main_quit())
actor = Clutter.Actor()
actor.set_background_color(Clutter.Color.get_static(Clutter.StaticColor.RED))
actor.set_reactive(True)
actor.set_size(32, 32)
stage.add_child(actor)
actor.set_position(82, 82)
def moveLeft(actor):
actor.set_x(20)
def moveRight(actor):
actor.set_easing_duration(1000)
actor.set_easing_mode(Clutter.AnimationMode.LINEAR)
actor.set_x(280)
actor.connect('transition-stopped::x', lambda a, n, t: moveLeft(actor))
actor.connect('button-press-event', lambda a, e: moveRight(actor))
stage.show()
Clutter.main()
it can be arbitrarily more complex than this; you also need to remember to disconnect the transition-stopped::x
signal handler, and restore the easing state to avoid creating implicit animations every time you change the actor's state, but I'll leave that as an exercise to the reader.