我试图将文本放在屏幕中央,同时在顶部标记中心的文本。为了目前使文本居中,我正在使用以下代码...
info = pygame.display.Info()
screen = pygame.display.set_mode((info.current_w, info.current_h), pygame.FULLSCREEN)
screen_rect = screen.get_rect()
txt = font.render("some random message", True, color)
screen.blit(txt, txt.get_rect(center=screen_rect.center))
但我无法找到一种使用get_rect()
来仅编辑y轴的方法。我也在文档中找不到更多关于get_rect()
函数的详细说明。
pygame.Rect
对象已经拥有所有这些属性,因此您不需要创建任何东西。 - Ted Klein Bergmanpygame.display.update()
?否则它不会更新屏幕。请创建一个完整的示例,包括游戏循环、事件处理和窗口更新。 - Ted Klein Bergmansceen.blit()
绘制到一个仅存在于内存中的 "图像"(内部缓冲区)。换句话说,它是不可见的。pygame.display.update()
获取 "图像" (缓冲区)并将其绘制到物理屏幕上,以便您可以看到它。如果没有pygame.display.update()
,您只能看到黑色(或者是最后一次更新到屏幕上的内容)。 - Ted Klein Bergman