gpt4 book ai didi

python - Pygame字体错误

转载 作者:太空狗 更新时间:2023-10-30 02:30:11 26 4
gpt4 key购买 nike

所以我决定开始制作游戏并对其进行了一些测试,然后我得到了这个错误:

Traceback (most recent call last):
File "TheAviGame.py", line 15, in <module>
font = pygame.font.Font(None,25)
pygame.error: font not initialized

到目前为止我不知道我做错了什么......代码:

#!/usr/bin/python
import pygame
blue = (25,25,112)
black = (0,0,0)
red = (255,0,0)
white = (255,255,255)
groundcolor = (139,69,19)
gameDisplay = pygame.display.set_mode((1336,768))
pygame.display.set_caption("TheAviGame")
direction = 'none'
clock = pygame.time.Clock()
img = pygame.image.load('player.bmp')
imgx = 1000
imgy = 100
font = pygame.font.Font(None,25)
def mts(text, textcolor, x, y):
text = font.render(text, True, textcolor)
gamedisplay.blit(text, [x,y])
def gameloop():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.pygame == pygame.KEYDOWN:
if event.key == pygame.RIGHT:
imgx += 10
gameDisplay.fill(blue)
pygame.display.update()
clock.tick(15)
gameloop()

最佳答案

您从未在导入后初始化 pygamepygame.font:

# imports

pygame.init() # now use display and fonts

关于python - Pygame字体错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28517979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com