如何将一个小部件向前旋转另一个



我想知道如何将一个小部件向前旋转另一个。以下是我所拥有的:(我使用散射和动画来旋转我的小部件,我不想在这里使用.kv文件(

terrain = Image(source = "terrain.png")
target = Image(source = "target.png", center = (300, 200))
terrain.add_widget(target)
arrow = Image(source = "arrow.png", center = (100, 150))
scatter = Scatter(rotation = 90) 
scatter.add_widget(arrow)
terrain.add_widget(scatter)
animation = Animation(center = (target.center_x, target.center_y), rotation = ____)#<forward target
animation.start(scatter)

希望你能回答,塔里兹。

我认为只使用上下文指令比使用Scatter小部件更简单。下面是一个例子(基于您发布的代码(:

class TestApp(App):
def build(self):
root = FloatLayout()  # use a Layout widget to contain the Images
terrain = Image(source = "terrain.png")
root.add_widget(terrain)
target = Image(source = "target.png", center = (300, 200))
root.add_widget(target)
self.arrow = Image(source = "arrow.png", center = (100, 150))
# set up Rotation using Context Instructions in the Canvas
with self.arrow.canvas.before:
PushMatrix()
self.arrow.rotate = Rotate(angle=0, origin=self.arrow.center)
with self.arrow.canvas.after:
PopMatrix()
root.add_widget(self.arrow)
# schedule the rotation
Clock.schedule_once(self.do_rotate, 2)
return root
def do_rotate(self, dt):
self.arrow.rotate.origin = self.arrow.center
animation = Animation(angle=-90)
animation.start(self.arrow.rotate)

相关内容

最新更新