[英]How to animate a kivy layout subclass?
I am subclassing kivy.uix.layout
. 我将kivy.uix.layout
子类kivy.uix.layout
。 The goal is to animate the child widgets by recalculating their position on each frame. 目标是通过重新计算子窗口小部件在每个帧上的位置来为子窗口小部件设置动画。
What's the correct way of doing this? 正确的做法是什么?
I can schedule a re-layout by doing this: 我可以通过以下方式安排重新布局:
self.layout_clock = Clock.schedule_interval(self._trigger_layout, -1)
But I get lots of errors: 但是我有很多错误:
[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
I guess by changing the childrens' positions inside of do_layout
, I trigger do_layout
again by some event binding and thus create an infinite loop, right? 我猜想通过更改do_layout
内孩子的位置,我do_layout
通过事件绑定再次触发do_layout
,从而创建一个无限循环,对吗?
So how do I do this? 那么我该怎么做呢?
I think, I have found the solution myself. 我想,我自己找到了解决方案。 Kinda. 金田
Referring to the chapter Schedule before frame in the docs, I thought a timeout
of -1
was what I needed as I wanted to first calculate all positions and then have the app draw all widgets there. 提到文档中的“ 框架之前的计划 ”一章,我认为我需要timeout
-1
,因为我想首先计算所有位置,然后让应用在此处绘制所有小部件。
However, this does the above mentioned mess-up. 但是,这样做会造成上述混乱。 I don't quite understand why this is causing the described callback loop. 我不太明白为什么这会导致所描述的回调循环。 If anybody likes to explain :-) 如果有人喜欢解释:-)
Anyway, what does work is a timeout
of either 0
or 1/60
(for a framerate of 60). 不管怎么说, 做的工作是一个timeout
的任一0
或1/60
(对于60帧率)。
self.layout_clock = Clock.schedule_interval(self._trigger_layout, 0)
Now all my widgets move buttery smooth and there's no more warnings. 现在,我所有的小部件都可以顺畅地移动,不再发出警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.