1
我想製作一個可以旋轉加載微調器圖像的動畫小部件。我已經研究過Animation
班,看起來它可以完成這項工作。但我無法找到一個方法來保持在一個方向上旋轉部件不斷如何在Kivy中製作重複的旋轉動畫?
這是我的代碼有:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.image import Image
from kivy.graphics import Rotate
from kivy.animation import Animation
from kivy.properties import NumericProperty
Builder.load_string('''
<Loading>:
canvas.before:
PushMatrix
Rotate:
angle: self.angle
axis: (0, 0, 1)
origin: self.center
canvas.after:
PopMatrix
''')
class Loading(Image):
angle = NumericProperty(0)
def __init__(self, **kwargs):
super().__init__(**kwargs)
anim = Animation(angle = 360)
anim += Animation(angle = -360)
anim.repeat = True
anim.start(self)
class TestApp(App):
def build(self):
return Loading()
TestApp().run()
當你啓動它,你會看到小部件旋轉360單向旋轉,然後轉動旋轉。我如何構建動畫序列,以便角度會不斷保持增長,或者每360次旋轉將會降至0?