Отображение текста на экране Pygame - PullRequest
0 голосов
/ 10 ноября 2019

Это часть моей программы

running = True
win_size = [800,600]
Color_screen=[201, 169, 167]
Color_line=(0,0,0)

# initialize pygame
pygame.init()
scr = pygame.display.set_mode(win_size)
pygame.display.set_caption('Traverse')
scr.fill(Color_screen)
pygame.display.flip()

# Drawing Traverse
for i in range(len(x)-1):
    pygame.time.delay(1000)
    pygame.draw.line(scr,Color_line,(x[i],y[i]),(x[i+1],y[i+1]))
    pygame.display.flip()

# Displaying Scale
font = pygame.font.Font('freesansbold.ttf', 32)
text = font.render(f'Scale : {scale} pixels = 1 metre', True, Color_line)
textRect = text.get_rect()
textRect.center = (100, 50)
scr.blit(text,[100,20])

while running:
    # looking for events
    for events in pygame.event.get():
        if events.type == QUIT:
            running = False
            pygame.quit()

Кажется, все работает нормально, за исключением того, что текст не отображается на экране. Траверс рисуется, но не текст. в коде чего-то не хватает?

1 Ответ

0 голосов
/ 10 ноября 2019

Вы должны обновить отображение Surface, либо pygame.display.flip() или pygame.display.update(), после того, как текст Поверхность будет blit:

font = pygame.font.Font('freesansbold.ttf', 32)
text = font.render(f'Scale : {scale} pixels = 1 metre', True, Color_line)
textRect = text.get_rect()
textRect.center = (100, 50)
scr.blit(text,[100,20])

pygame.display.flip() # <---
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...