【发布时间】:2017-07-27 23:42:13
【问题描述】:
我一直在玩How to make a repetitive rotating animation in Kivy? 的代码。在下面的代码中,我使用它来旋转 45RPM 记录的图像。我想将记录的位置从屏幕中心更改为在屏幕右上角旋转。
我已搜索但找不到任何有关如何将图像重新定位到右上角的信息和/或有关如何确保图像在移动后保持正确旋转的信息。
我将不胜感激。
提前致谢。
....布拉德....
代码图片位于:https://drive.google.com/open?id=0B-T2cvsAoZ2vQ2hmaHM0SnlQVlU
# Modified from https://stackoverflow.com/questions/41321832/how-to-make-a-repetitive-rotating-animation-in-kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.animation import Animation
from kivy.properties import NumericProperty
Builder.load_string('''
<Loading>:
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: root.center
canvas.after:
PopMatrix
Image:
source: '45rpm.png'
size_hint: None, None
size: 200, 200
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
''')
class Loading(FloatLayout):
angle = NumericProperty(0)
def __init__(self, **kwargs):
super(Loading, self).__init__(**kwargs)
anim = Animation(angle = 360, duration=2)
anim += Animation(angle = 360, duration=2)
anim.repeat = True
anim.start(self)
def on_angle(self, item, angle):
if angle == 360:
item.angle = 0
class RotationAnimation(App):
def build(self):
return Loading()
RotationAnimation().run()
【问题讨论】:
标签: kivy