При обновлении текста прошлый не изчезает

Рейтинг: 0Ответов: 1Опубликовано: 14.05.2023
import pygame
import pygame_widgets
from pygame_widgets.button import Button

import time
pygame.init()
pygame.font.init()
win = pygame.display.set_mode((1200, 700))

DTMONO = pygame.font.Font('Fonts/determinationmonorusbylyajk_0.otf', 30)
fontx=14
fonty=14
money=0
def moneyq():
 moneyText=DTMONO.render("Souls: "+str(money),False, (255, 255, 0))
 win.blit(moneyText, (100,100))     

moneyTexa = pygame.display.get_surface()
def ClickMoney():
    global money
    global moneyText
    money+=1
    print(money)
ClickSouls = Button(
win,
normal_border=(0,255,0),
x = 200,
y = 200,
width = 200,
height = 200,
onClick=ClickMoney)





run = True
while run:
    pygame.display.update()
    
    events = pygame.event.get()
    pygame_widgets.update(events)
    moneyq()
    for event in events:
        if event.type == pygame.QUIT:
            pygame.quit()
            run = False
            quit()
    

      # Call once every loop to allow widgets to render and listen

Текст вместо перезаписи наслаивается, что делать?

Ответы

▲ 1Принят

Чтобы очистить экран в pygame нужно перед отрисовке других элементов добавить
win.fill((0, 0, 0)) вот так:

import pygame
import pygame_widgets
from pygame_widgets.button import Button

import time

pygame.init()
pygame.font.init()
win = pygame.display.set_mode((1200, 700))

DTMONO = pygame.font.SysFont('arial', 30)
fontx = 14
fonty = 14
money = 0


def moneyq():
    moneyText = DTMONO.render("Souls: " + str(money), False, (255, 255, 0))
    win.blit(moneyText, (100, 100))


moneyTexa = pygame.display.get_surface()


def ClickMoney():
    global money
    global moneyText
    money += 1
    print(money)


ClickSouls = Button(
    win,
    normal_border=(0, 255, 0),
    x=200,
    y=200,
    width=200,
    height=200,
    onClick=ClickMoney)

run = True
while run:
    pygame.display.update()
    win.fill((0, 0, 0))

    events = pygame.event.get()
    pygame_widgets.update(events)
    moneyq()
    for event in events:
        if event.type == pygame.QUIT:
            pygame.quit()
            run = False
            quit()

    # Call once every loop to allow widgets to render and listen