本文共 563 字,大约阅读时间需要 1 分钟。
一、使用文字需要导入一个方法 freetype
具体方法 pygame.freetype.Font(“C:\Windows\Fonts\方正粗黑宋简体.ttf”,24) 前者表示字体类型,后者表示字体大小 字体类型在电脑的c盘Windows >>fonts文件下import pygame,sysimport pygame.freetypepygame.init()pos=[150,150]GOLD=255,251,0BLACK=0,0,0screen=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()
转载地址:http://otmzi.baihongyu.com/