PyGame菜单格式

时间:2015-05-26 18:26:20

标签: python visual-studio-2010 pygame

所以我最近一直在用Python编写游戏以及一个名为PyGame的外部库。如果有人熟悉Hearthstone游戏,那就是我想要的感觉。然而,这是重点。我已经研究过如何显示图像及其位置,我一直试图在PyGame UI中创建一个带按钮的菜单。我以前在Visual Basic中编程,我想知道PyGame接口是否允许一般的系统事件检测,与Visual Basic(即鼠标点击,按键)不同。非常感谢帮助。提前谢谢!

2 个答案:

答案 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图像到显示屏的链接:

链接:

- Recthttp://www.pygame.org/docs/ref/rect.html#pygame.Rect

- Surfacehttp://www.pygame.org/docs/ref/surface.html#pygame.Surface

- imagehttp://www.pygame.org/docs/ref/image.html

答案 1 :(得分:0)

  

我想知道PyGame接口是否允许一般的系统事件检测,与Visual Basic

不同

简答:不。 Pygame不是事件驱动的。你必须自己编写所有东西,因为pygame只是SDL的一个小包装器,带有一些额外的功能。

或许请查看提供此类事件循环的cocos2dpyglet