Я создаю очень простую игру, чтобы попытаться разобраться в ней, но столкнулся с проблемой довольно рано.
Я попытался изменить положение, когда таймер обновляется, но он продолжает мигать / мигать.
def update_timer():
global timer, timerrect
# make timer text
displaytext(f"{counter}", 50, 50)
# dispay timer
pygame.display.flip()
return timer, timerrect
def displaytext(text, a, b):
x = font.render(text, True, BLACK, WHITE)
xrect = x.get_rect()
xrect.center = (a, b)
screen.blit(x, xrect)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.USEREVENT:
counter-=1
update_timer()
# not-so-elegant displaying of timer
try:
screen.blit(timer, timerrect)
pygame.display.flip()
except:
pygame.display.flip()
# some more code here
# draw all sprites
all_sprites.draw(screen)
# fps
clock.tick(60)
# update screen
pygame.display.flip()
Как я уже говорил, таймер постоянно мигает.Я бы хотел, чтобы это не вызывало судороги /s.