我想知道如何將一個小部件向前旋轉。這是我所擁有的:(我使用分散和影片來旋轉我的小部件,我不想在這里使用 .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)
希望你能回答,Tarezze。
uj5u.com熱心網友回復:
我認為只使用背景關系指令而不是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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/521016.html
上一篇:從R中的資料創建列聯表
下一篇:關鍵幀小鬼?
