所以我最近一直在用Python编写游戏以及一个名为PyGame的外部库。如果有人熟悉Hearthstone游戏,那就是我想要的感觉。然而,这是重点。我已经研究过如何显示图像及其位置,我一直试图在PyGame UI中创建一个带按钮的菜单。我以前在Visual Basic中编程,我想知道PyGame接口是否允许一般的系统事件检测,与Visual Basic(即鼠标点击,按键)不同。非常感谢帮助。提前谢谢!
答案 0 :(得分:0)
需要进行while
循环才能在pygame中进行事件检测。这是一个例子:
import time
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
#happens when 'X' in window is clicked
#put code to be executed here
elif event.type == pygame.MOUSEBUTTONDOWN:
onclick_function(pygame.mouse.get_pos)
#passes mouse position as tuple to function to deal with click control.
当将图像blitting到显示器时,需要知道坐标。只需保留一个Rect
对象列表,每个对象都有一个单击它们时要执行的函数,并使用函数迭代列表并查看鼠标的坐标是否在Rect
内。 / p>
查看blitting图像到显示屏的链接:
链接:
- Rect
:http://www.pygame.org/docs/ref/rect.html#pygame.Rect
- Surface
:http://www.pygame.org/docs/ref/surface.html#pygame.Surface
答案 1 :(得分:0)