【问题标题】:Pygame Text Doesn't DisplayPygame 文本不显示
【发布时间】:2021-07-22 23:13:22
【问题描述】:
def score():
    global x_score, o_score
    
    scoreFont = pygame.font.SysFont('Comic Sans', 20, bold=True)
    SCORE = scoreFont.render(f'X   {x_score} : {o_score}   O', True, (0, 0, 0))
    screen.blit(SCORE, ((WIDTH / 2) - (SCORE.get_width() / 2), HEIGHT + SCORE.get_height()))
  • WIDTH 和 HEIGHT = 屏幕宽度和高度

  • 定义了 x 和 o 分数

  • pygame 和字体都是从一开始就初始化的

  • 函数后调用pygame.display.flip()

我的代码中的其他所有内容都显示了这个。谁能帮助我并告诉我在尝试显示分数时我做错了什么?

【问题讨论】:

    标签: python pygame text-rendering


    【解决方案1】:

    分数在窗口外的底部。更改 y 坐标的计算。垂直位置是HEIGHT - SCORE.get_height()而不是HEIGHT + SCORE.get_height()

    screen.blit(SCORE, ((WIDTH / 2) - (SCORE.get_width() / 2), HEIGHT + SCORE.get_height()))

    screen.blit(SCORE, ((WIDTH / 2) - (SCORE.get_width() / 2), HEIGHT - SCORE.get_height()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多