python - Clutter messing up animations -


clutter not doing full animation.

this current code:

from gi.repository import clutter, gtk import sys  def onclick(actor, event):     actor.animatev(clutter.animationmode.linear, 1000, ["x"], [280])  # clutter not seem running line     actor.animatev(clutter.animationmode.linear, 1000, ["x"], [20])  def main():     clutter.init(sys.argv)      # colors     red = clutter.color().new(255, 0, 0, 255)     black = clutter.color().new(0, 0, 0, 255)      # create stage     stage = clutter.stage()     stage.set_title("basic usage")     stage.set_size(400, 200)     stage.set_color(black)      # rectangle actor     actor = clutter.rectangle()     actor.set_size(100, 50)     actor.set_position(150, 100)     actor.set_color(red)     actor.set_reactive(true)     actor.connect("button-press-event", onclick)      # add actor stage     stage.add_actor(actor)     stage.connect("destroy", lambda w:  clutter.main_quit())     stage.show_all()      clutter.main()  if __name__ == '__main__':     main() 

behold illustration of problem:

enter image description here

for of don't gifs, here problem described in words: want actor move middle right, way left. instead moves middle straight left.

what causing this, , how can fix it?

like documentation clutteractor.animate() says:

calling function on actor being animated cause current animation change new final values, new easing mode , new duration https://developer.gnome.org/clutter/stable/clutter-implicit-animations.html#clutter-actor-animate

which means following code:

actor.animatev(clutter.animationmode.linear, 1000, ["x"], [280]) actor.animatev(clutter.animationmode.linear, 1000, ["x"], [20]) 

is equivalent to:

actor.animatev(clutter.animationmode.linear, 1000, ["x"], [20]) 

which you're seeing.

if want chain 2 animations have connect completed signal of clutteranimation, using connect_after function, clutter can create 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 point out animatev() , clutteranimation deprecated; can replaced using explicit clutter.keyframetransition or implicit transition, 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 arbitrarily more complex this; need remember disconnect transition-stopped::x signal handler, , restore easing state avoid creating implicit animations every time change actor's state, i'll leave exercise reader.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -