python - pygame - 如何将文本写入特定位置?另外,如何使用坐标

标签 python pygame python-3.3

我一直在四处搜寻,但我真的找不到任何关于如何编写文本的好资源?我试过使用文本渲染命令,但它对我不起作用。

还有,当你在这里的时候;是否有一种“覆盖”类型的东西,您可以在其中准确看到坐标的位置?每次我使用坐标来确定一个区域时,我真的无法弄清楚整个坐标系是如何工作的,除了反复试验之外……

非常感谢,

最佳答案

surf = pygame.display.set_mode((WIDTH, HEIGHT))

...

# get font object
font = pygame.font.SysFont('Arial', 12, bold=True)    

# render a given font into an image
img = font.render('Text to write', True,
                  pygame.Color(FONT_FG_COLOR),
                  pygame.Color(FONT_BG_COLOR))

# and finally put it onto the surface.
# the code below centres text image
surf.blit(img, ((surf.get_width() - img.get_width())/2,
                (surf.get_height() - img.get_height())/2))

关于python - pygame - 如何将文本写入特定位置?另外,如何使用坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20550743/

相关文章:

python - MLP 与 keras 进行预测

python - 在修补导入的模块时模拟返回 ImportError

python - 在 python 3.3 中安装 suds

python - 升级后的Pylab

python - 如何使用 Tkinter 设置网格的位置?

python - 在 Python 中,如何将列表中的所有元素添加到集合中?

python - pandas 从日期范围列中提取开始和结束日期

python - Pygame 屏幕在我关闭时卡住

python - Py2exe (Python Pygame) - 难道没有更简单的方法吗?

python - float 对象没有属性 __getitem__