pygameを使用してテキストを描画する

3774 ワード

一、文字を使うには、freetypeの具体的な方法pygame.freetype.Font(「C:WindowsFonts方正粗黒宋簡体.ttf」、24)をインポートする必要があります.前者はフォントタイプを表し、後者はフォントサイズフォントタイプがパソコンのcディスクWindows>>fontsファイルの下にあることを表します.
import pygame,sys
import pygame.freetype
pygame.init()
pos=[150,150]
GOLD=255,251,0
BLACK=0,0,0
screen=pygame.display.set_mode((600,400))
pygame.display.set_caption("    ")
f1=pygame.freetype.Font("C:\Windows\Fonts\       .ttf",24)
f1rect=f1.render_to(screen,pos,"    ,    ",fgcolor=GOLD,bgcolor=BLACK,)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        pygame.display.update()