Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Layer animate 'rotate' question
-
I am working with the layer.animate('rotate' scene function and it works as expected. I do not understand how to rotate something back and forth - say +90 and then -90.
This combination does not work - only the second call seems to execute:
self.layer.animate('rotation', self.layer.rotation + 90, duration=0.25, autoreverse=True) self.layer.animate('rotation', self.layer.rotation - 90, duration=0.25, autoreverse=True)
and so I tried this which also does not work:
self.layer.animate('rotation', self.layer.rotation + 90, duration=0.25, autoreverse=True) self.layer.animate('rotation', self.layer.rotation - 90, duration=0.25, delay=0.25, autoreverse=True)
does this mean I have to execute the second animate via a completion function, or is there a way to hack a curve that would cause it to mirror + to -?
-
Unlike ui animations, I think scene only lets you have an active animation one at a time for a given attribute.
The key to chaining animations is to use thecompletion
argument:from scene import * import sys class MyScene (Scene): def setup(self): self.layer = Layer(Rect(self.size.w * 0.5 - 100, self.size.h * 0.5 - 100, 200, 200)) self.layer.background = Color(1, 0, 0) def clockwise(completion=None): self.layer.animate('rotation', self.layer.rotation+90, duration=1.0, autoreverse=True,completion=completion) def counterclockwise(completion=None): self.layer.animate('rotation', self.layer.rotation-90, duration=1.0, autoreverse=True,completion=completion) clockwise(counterclockwise) def draw(self): background(0, 0, 0) self.layer.update(self.dt) self.layer.draw() run(MyScene())