0
'''
start_msg = welcome_screen.render("Press Y to start or autostart in 10 seconds", True, (255,255,255))
startmsg_rect = welcome.get_rect(center = (int(displayWidth/2), int(displayHeight/3)))


display.blit(start_msg, startmsg_rect)

pygame.display.flip()
'''

The text isn't coming as center-aligned.

halfer
  • 19,824
  • 17
  • 99
  • 186
Krish Arora
  • 19
  • 1
  • 3

2 Answers2

0

What is welcome?

The startmsg_rect should come from start_msg, the rendered text. That way, the startmsg_rect has the correct dimensions, allowing the text to be visibly centered in a convenient way with the center argument.

startmsg_rect = start_msg.get_rect(center = (displayWidth/2, displayHeight/3))

Also I believe the arguments to center don't have to be ints, they will be rounded or truncated by the rect itself.

Starbuck5
  • 1,649
  • 2
  • 7
  • 13
0

The text is not aligned to the center, because the height is divided by 3. Further more you need to get the bounding rectangle of the text (start_msg):

startmsg_rect = welcome.get_rect(center = (int(displayWidth/2), int(displayHeight/3)))

startmsg_rect = start_msg.get_rect(center = (displayWidth // 2, displayHeight // 2)

Alternatively you can get the display Surface with pygame.display.get_surface

screen_center = pygame.display.get_surface().get_rect().center
startmsg_rect = start_msg.get_rect(center = screen_center)
display.blit(start_msg, startmsg_rect)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174