-1

I am trying to create a small game. I made a score tracker with font.Font .

points = 0
score_text = pygame.font.Font('Pixeltype.ttf',100)
score_surf = score_text.render(f'Current points: {points}', None, 'Green')

This is before the while True loop that starts the game. This is pure variable declaration.

Later below, as i defeat 'enemies', I add +100 points to points.

Although my score does not update with screen.blit(score_surf,(850,40)), if i call print(points), my points have indeed increased.

I tried creating a separate text element for the points, still had this problem.

I am new to pygame module and i figured out I should practice the stuff i learned before moving on.

Thanks a lot in advance!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

0

The problem is in this line

score_surf = score_text.render(f'Current points: {points}', None, 'Green')

Expression f'Current points: {points}' gets evaluated only once to variable and passed to the render. It isn't function returning string but only formatted string.

You have to render score_surf again after it is changed.

How to fix it

See this answer.

Přemysl Šťastný
  • 1,676
  • 2
  • 18
  • 39