【发布时间】:2021-03-31 19:23:36
【问题描述】:
我有这段代码,它没有在屏幕宽度的中间显示分配给变量“title”的文本。 除了根据文本的长度猜测位置之外,还有什么方法可以将其居中?
import pygame
pygame.init()
pygame.font.init()
WIDTH = 1920
HEIGHT = 1080
CYAN = (0, 255, 255)
RED = (255, 0, 0)
window = pygame.display.set_mode((WIDTH, HEIGHT))
def startWindow():
titleFont = pygame.font.SysFont("Comic Sans MS", 35)
window.fill(RED)
title = titleFont.render("Ball Game", False, CYAN)
window.blit(title, (WIDTH//2, 35))
pygame.display.update()
startWindow()
【问题讨论】: