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() –