0

Hi and thanks in advance. I'm working in Pygame and the score and stopwatch variables I try to display as text change position on screen depending on whether they have 10s or 100s place. How can I center or align text so it doesn't jump around on the screen in between the 1s, 10s, or 100s place. See images below. First image "1" is 1 point, second image "10" is 10 points

Basically, I think if I can align to left, then this might solve it. Here's my code below: '''

for event in pygame.event.get():
        print("For Event started, Game screen started")
        screen.fill((255,255,255))
        screen.blit(Bg_screen[0], (0,0))
        screen.blit(Game_screen[8], (110,9))
        score_text = score_font.render(str(score), 3, "red")
        score_rect = score_text.get_rect(center = screen.get_rect().center)
        screen.blit(score_text, (580,470))
        pygame.display.update()
        if event.type == pygame.JOYBUTTONDOWN:
            print("If then, event type started")
            if event.button == random_num:
                B = event.button
                print(B, " button pressed, CORRECT")
                leds.off()
                random_num = random.randint(0, 11)
                leds.on(random_num)
                print(random_num)
                score += 1
    current_Time = int(time.time())
    time_Out = current_Time - start'''
Rabbid76
  • 177,135
  • 25
  • 101
  • 146

1 Answers1

0

Define the center of the text and center the text rectangle on the center point. Use the rectangle to blit the text:

score_text = score_font.render(str(score), 3, "red")

center_pos = (640, 520) # just for example
score_rect = score_text.get_rect(center = center_pos)

screen.blit(score_text, score_rect)

In the example above, the center point is (640, 520). You have to play around with this position and adjust it to suit your needs.

Rabbid76
  • 177,135
  • 25
  • 101
  • 146