When using surface.blit
during a mouse event, the blit doesn't remain on the screen.
I have two almost identical images. The standard image already exists on the surface and when the mouse hovers over the image, another image needs to be placed on top of the existing image and when the mouse leaves the image it needs to be removed.
My current code works except a mouse event needs to be going on - when the mouse is stationary inside the image, the overlay image is removed. How do I fix this?
def Execute(self):
while self.Running == True:
NewGameButton = pygame.image.load("./Assets/Interface/newgame.png").convert_alpha()
NewGameButtonHover = pygame.image.load("./Assets/Interface/newgame_hover.png").convert_alpha()
self.Display.blit(NewGameButton, (460,260))
pygame.display.flip()
for Event in pygame.event.get():
if NewGameButton.get_rect(topleft=(460,260)).collidepoint(pygame.mouse.get_pos()):
self.Display.blit(NewGameButtonHover, (460,260))
pygame.display.update()
pygame.quit()
Note: The Execute()
function is a method within the class App
.