0

I am creating a clicker game and while just starting I am making the overall button you click to increase money. While the score increases all and well, when blitting the score to the screen, it doesn't update the score, it just puts it over the previous one like here. Here is my code:

import pygame
import button

SCREEN_WIDTH = 700
SCREEN_HEIGHT = 900

pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Cocaine Clicker')
clock = pygame.time.Clock()
screen.fill('lightblue')
font = pygame.font.Font('Pacifico-Regular.ttf', 100)

score = 0
score_increase_factor = 1

def disp_score(score):
    score_surf = font.render(f'${score}', False, (0,0,0))
    score_rect = score_surf.get_rect(center = (350, 50))
    screen.blit(score_surf, score_rect)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

    disp_score(score)

    if money_sprite.draw(screen):
        score = score + score_increase_factor
        print(score)

    pygame.display.update()
    clock.tick(60)

Button is a different file with a class that creates the button mechanics. I am new to code so if there is anythig else you need please ask, thank you.

1 Answers1

1

Each time you call 'disp_score' you are drawing over what you have previously drawn. You can avoid this by redrawing the screen. They explain the concept in more depth at the beginning of this document: https://www.pygame.org/docs/tut/MoveIt.html