2
def main():  #my main loop 
running = True
clock = pygame.time.Clock()  # A clock to limit the frame rate.
score = (0)
score = str(score)
myfont = pygame.font.SysFont('OpenSans', 30)        
textsurface = myfont.render('Level ONE:   Greenland', False, (0, 0, 0))        
background.blit(textsurface,(500,10))

the score is converted to sting to that it can be displayed on the screen but its converted back into an integer when adding the score

textsurface = myfont.render(score, False, (0, 0, 0))        
background.blit(textsurface,(10,10))
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    player_hit_list = pygame.sprite.spritecollide(player, enemy_list, True)
    for enemy in player_hit_list:
        pygame.quit()
    player_hit_list = pygame.sprite.spritecollide(player, coin_list, True)


    for coin in player_hit_list:
        textsurface = myfont.render(score, False, (0, 0, 0))        
        background.blit(textsurface,(10,10))
        score = int(score)+ 1
        score = str(score)
        print(score)

here i am trying to make the score update on to the screen when the character touches a coin but it overlaps with the previous score e.g. 0,1,2,3. so i need to get rid of the previous score.

bob
  • 47
  • 5

1 Answers1

0
textsurface = myfont.render(score, False, (0, 0, 0))        
background.blit(textsurface,(10,10))
while running:

    screen.fill(WHITE)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    player_hit_list = pygame.sprite.spritecollide(player, enemy_list, True)
    for enemy in player_hit_list:
        pygame.quit()
    player_hit_list = pygame.sprite.spritecollide(player, coin_list, True)


    for coin in player_hit_list:
        textsurface = myfont.render(score, False, (0, 0, 0))        
        background.blit(textsurface,(10,10))
        score += 1
        print("{0}".format(score))

Python/Pygame How to make my Score Text update itself forever?

naivepredictor
  • 898
  • 4
  • 14