如何在pygame中显示utf-8角色



有没有一种方法可以使用pygame渲染记号?我试着像这样直接使用unicode:

def write(screen, text, color, position, size):
font = pygame.font.Font(pygame.font.get_default_font(), size)# Defining a font with font and size
text_surface = font.render(text, True, color)# Defining the text color which will be rendered
screen.blit(text_surface, (position[0], position[1])) # Rendering the font
write(window, u'u2713', self.color, position, size) 

但这只是画了一个矩形。

正在写入的这个"矩形"实际上是使用pygame.font.get_default_font()符号的表示。为了显示符号,您需要确保此符号包含在您正在使用的字体中。我提出以下解决方案:

  1. 下载包含此符号的字体(例如,Segoe UI符号(
  2. 将字体包解压缩到数据文件夹(或主应用程序文件夹(中
  3. 将您使用的字体更改为下载的字体
font = pygame.font.Font("seguisym.ttf", size)
  1. 使用write(window, u'u2713', self.color, position, size)方法或直接使用write(screen, "✓", self.color, position, size)使用写入函数

最新更新