1

code responsible for creating the buttons.

    def __init__(self, str, x, y):
    font = pygame.font.Font(None, 60)
    text = font.render(str, 0, (0, 0, 0))
    textpos = text.get_rect()

    self.surface = pygame.Surface((300, textpos.height + 10))
    self.surface.fill((0, 255, 0))
    #self.surface.set_colorkey((0, 255, 0))
    self.surfacepos = self.surface.get_rect()
    textpos.centerx = self.surfacepos.centerx
    textpos.centery = self.surfacepos.centery
    self.surface.blit(text, textpos)
    self.surfacepos.centerx = x
    self.surfacepos.top = y

code that checks where the mouse was pressed

    if event.type == MOUSEBUTTONUP:
        pos = pygame.mouse.get_pos()
        if credito.surfacepos.collidepoint(pos):

there are multiple buttons and they all work fine, except for the last one that's placed close to the bottom of the screen. More specifically, only a small area below the actual text seems to work.

picture showing the area that's actually working:

i already moved this button to other positions and it worked, but i wonder what's causing this

Edit: i also found out that, if i simply remove the ` from the string, the collision seems to stop working completely, plus if i create another button and move this new one to the same position, it works fine. i think it might be related to the strings given somehow.

code of the generation of the button objects.

play = Button("JOGAR", new_screen.get_rect().centerx, new_screen.get_rect().centery)
new_screen.blit(play.surface, play.surfacepos)
help = Button("INSTRUÇÕES", new_screen.get_rect().centerx, new_screen.get_rect().centery+100)
new_screen.blit(help.surface, help.surfacepos)
credito = Button("CRÉDITOS", new_screen.get_rect().centerx, new_screen.get_rect().centery+200)
new_screen.blit(credito.surface, credito.surfacepos)
back = Button("VOLTAR", -300, -300)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
PopocaDice
  • 11
  • 3

0 Answers0