0
我想用Python和Kivy做一個Pong遊戲,但是我不能改變球的位置。每當我嘗試時,除非我在課堂內調用我不想做的方法,否則球不會改變。如何從Python中的另一個類的另一個類訪問方法以編輯Kivy對象?
的Python:
#Imported everything
class PongGame(Widget):
ball = ObjectProperty()
def update(self):
self.ball.pos = (1200, 1200)
class PongBall(Widget):
pass
class PongApp(App):
def build(self):
PongGame().update() #Doesn't work (doesn't do anything)
print(PongGame().ball.pos)) #Not even printing right coordinates
return PongGame()
if __name__ = "__main__":
PongApp().run()
的Kv:
<PongGame>:
ball: pball
PongBall:
id: pball
pos: (root.center_x - (root.width * 0.05), root.center_y * (1/12))
size: (root.height * (1/20), root.height * (1/20))
<PongBall>:
canvas:
Color:
rgb: [1, 1, 1]
Ellipse:
pos: self.pos
size: self.size
嘗試去除高清更新(個體經營)自我? – Stephan
那麼我會如何訪問ObjectProperty球? –
我認爲這是一個運行PongGame()的問題。update() –