我正在开发一个使用Thorpy作为图形用户界面元素的PyGame项目.我已经创建了连接到PyGame表面的Thorpy按钮.当我使用blit
函数移动曲面时,按钮的视觉表示会移动,但它们的点击框保持不变,从而导致点击问题.
在本例中,Thorpy按钮附加到蓝色曲面,它们的视觉表示是其点击框右侧的100个像素.
import pygame
import thorpy as tp
pygame.init()
def GUI_elements():
tp.init(surface, tp.theme_round)
button1 = tp.Button('Main Menu')
button2 = tp.Button('Exit Game')
group = tp.Group([button1, button2], 'v')
game_GUI = group.get_updater()
return game_GUI
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Pygame Window")
surface = pygame.Surface((400, 800))
def main_loop():
game_GUI = GUI_elements()
menu_button = game_GUI.element.children[0]
menu_button.at_unclick = exit
exit_button = game_GUI.element.children[1]
exit_button.at_unclick = exit
while True:
game_GUI.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((255, 0, 0))
screen.blit(surface, (100, 0)) # (100, 0) is the offset
surface.fill((0, 0, 200))
pygame.display.flip()
if __name__ == '__main__':
main_loop()
pygame.quit()
我试过移动Thorpy组或按钮,这很好用,但我看不出这如何解决我的问题,因为我仍然必须移动PyGame表面到它的理想位置,这将抵消一切.