【发布时间】:2021-11-26 18:33:31
【问题描述】:
我正在用 kivy 制作游戏,我希望图像仅在按下图像时移动,但目前,如果按下屏幕中的任何位置,图像就会移动。下面是我的代码!
main.py
class Ball(Image):
velocity = NumericProperty(0)
def on_touch_down(self, touch):
self.source = "icons/ball.png"
self.velocity = 275
super().on_touch_down(touch)
def on_touch_up(self, touch):
self.source = "icons/ball.png"
super().on_touch_up(touch)
class MainApp(App):
GRAVITY = 300
def move_ball(self, time_passed):
ball = self.root.ids.game_screen.ids.ball
ball.y = ball.y + ball.velocity * time_passed
ball.velocity = ball.velocity - self.GRAVITY * time_passed
main.kv
Ball:
source: "icons/ball.png"
size_hint: None, None
size: 500, 500
pos_hint: {"center_x": 0.5}
id: ball
【问题讨论】:
标签: python kivy kivy-language