I don't understand why old image doesn't clearing and a new image layering over old image in debug
import pygame
from setting import WIN_HEIGHT, WIN_WIDTH
from debug import debug
from pygame.locals import (
K_ESCAPE,
KEYDOWN
)
pygame.init()
# Rise text rectangular
def text_objects(text, font, color):
text_surf = font.render(text, True, color)
return text_surf, text_surf.get_rect()
# Make button
def button(screen, color, x, y):
pygame.draw.rect(screen, color, (x, y, WIN_WIDTH/11, WIN_HEIGHT/11), 0, 15)
# Pause menu
def paused(main_txt):
screen = pygame.display.get_surface()
text = pygame.font.SysFont("comicsansms",115)
text_surf, text_rect = text_objects(main_txt, text, 'black')
text_rect.center = ((WIN_WIDTH/2), (WIN_HEIGHT/3))
screen.fill((120, 120, 120))
screen.blit(text_surf, text_rect)
while paused:
music = pygame.mixer.music
music.pause()
resume = button(screen, 'green', WIN_WIDTH/3, WIN_HEIGHT/1.95)
exit = button(screen, (200, 0, 0), WIN_WIDTH/1.77, WIN_HEIGHT/1.95)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
pygame.quit()
elif (event.type == KEYDOWN and event.key == K_ESCAPE):
music.unpause()
return
mouse = pygame.mouse.get_pos()
debug(mouse)
if WIN_WIDTH/3 + WIN_WIDTH/11 > mouse[0] > WIN_WIDTH/3 and WIN_HEIGHT/1.95 + WIN_HEIGHT/11 > mouse[1] > WIN_HEIGHT/1.95:
button(screen, 'black', WIN_WIDTH/3, WIN_HEIGHT/1.95)
else:
resume
pygame.display.update()
pygame.time.Clock().tick(60)
The debug
function is
import pygame
pygame.init()
font = pygame.font.Font(None, 30)
def debug(info, y = 10, x = 10):
disp_surf = pygame.display.get_surface()
debug_surf = font.render(str(info), True, 'Red')
debug_rect = debug_surf.get_rect(topleft = (x,y))
disp_surf.blit(debug_surf, debug_rect)