I'm working on a Pygame project using Thorpy for GUI elements. I've created Thorpy buttons attached to a Pygame surface. When I move the surface using the blit
function, the visual representation of the buttons moves, but their hitboxes remain fixed, causing clicking issues.
In this example, the Thorpy buttons are attached to the blue surface and their visual representation is 100 pixels to the right of their hitboxes.
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()
I've tried moving the Thorpy group or buttons which works fine but I don't see how that would fix my problem because I still have to move the Pygame surface to it's ideal location which would then offset everything.