我想將轉換矩陣應用于小部件。在本例中,我預計它向右移動 100。然而它卻一動不動,而是Transformation:
x: 100效果很好。我已經簡化了問題,我實際上想從這里應用一些矩陣。此外,我從那里測試了一些矩陣,它的工作方式不同或者只是沒有顯示任何內容。from kivy.graphics.transformation import Matrixfrom kivy.lang import Builderfrom kivy.uix.anchorlayout import AnchorLayoutfrom kivy.app import AppBuilder.load_string("""<MainScreen>: anchor_x: "center" anchor_y: "center" canvas.before: Color: rgba: (0, 0, 0, 1) Rectangle: pos: self.pos size: self.size Button: id: widg size_hint: (0.3, 0.6) canvas.before: PushMatrix # Translate: # x: 100 MatrixInstruction: matrix: root.matrix canvas.after: PopMatrix text: "hello"""")class MainScreen(AnchorLayout): matrix = Matrix() matrix.set(array=[[1.0, 0.0, 0.0, 100.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]) def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) print(self.ids.widg.canvas.before.children[1].matrix)class Application(App): def __init__(self, **kwargs): super(Application, self).__init__(**kwargs) def build(self): return MainScreen()if __name__ == "__main__": Application().run()
1 回答

汪汪一只貓
TA貢獻1898條經驗 獲得超8個贊
你的矩陣不正確。嘗試:
matrix.set(array=[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [100.0, 0.0, 0.0, 1.0]])
添加回答
舉報
0/150
提交
取消