Python Pygame IOError,无法读取字体文件

Python Pygame IOError,无法读取字体文件,python,fonts,raspberry-pi,pygame,ioerror,Python,Fonts,Raspberry Pi,Pygame,Ioerror,我最近在Pygame中下载了一个im制作的游戏字体,但是当使用字体的提示弹出时,会显示一个错误。 错误内容如下: Traceback (most recent call last): File "/home/pi/Desktop/Python Game.py", line 83, in <module> game_loop() File "/home/pi/Desktop/Python Game.py", line 78, in game_loop crash() File "/ho

我最近在Pygame中下载了一个im制作的游戏字体,但是当使用字体的提示弹出时,会显示一个错误。 错误内容如下:

Traceback (most recent call last):
File "/home/pi/Desktop/Python Game.py", line 83, in <module> game_loop()
File "/home/pi/Desktop/Python Game.py", line 78, in game_loop crash()
File "/home/pi/Desktop/Python Game.py", line 29, in message_display largeText = pygame.font.Font 
("/home/pi/.fonts/ARCADECLASSIC.TTF",110)
IOError: unable to read font file '/home/pi/.fonts/ARCADECLASSIC.TTF'
我不知道发生了什么,因为我从另一个网站下载了相同的字体,这意味着它没有被破坏

我在一个树莓皮2运行树莓喘息。 这是我所有的代码(如果有必要):

导入pygame
导入时间
pygame.init()
显示宽度=800
显示高度=600
gameDisplay=pygame.display.set_模式((显示宽度、显示高度))
pygame.display.set_标题(“道路障碍物!”)
黑色=(0,0,0)
白色=(255255)
红色=(255,0,0)
轿厢宽度=50
clock=pygame.time.clock()
carImg=pygame.image.load(“Racecar.png”)
def汽车(x,y):
游戏显示.blit(carImg,(x,y))
def text_对象(文本、字体):
textSurface=font.render(文本,真,黑色)
返回textSurface,textSurface.get_rect()
def信息_显示(文本):
largeText=pygame.font.font(“ARCADECLASSIC.TTF”,110)
TextSurf,TextRect=text\u对象(text,largeText)
text rect.center=((显示宽度/2),(显示高度/2))
blit(TextSurf,TextRect)
pygame.display.update
时间。睡眠(2)
博弈循环
def crash():
信息显示(“哇!你崩溃了!”)
def game_loop():
x=(显示宽度*0.45)
y=(显示高度*0.8)
x_变化=0
gameExit=False
不退出游戏时:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
gameExit=True
如果event.type==pygame.KEYDOWN:
如果event.key==pygame.K_左:
x_变化+=-5
elif event.key==pygame.K_RIGHT:
x_变化+=5
如果event.type==pygame.KEYUP:
如果event.key==pygame.K_左:
x_变化+=5
如果event.key==pygame.K_RIGHT:
x_变化+=-5
x+=x_变化
游戏显示。填充(白色)
汽车(x,y)
如果x>显示宽度-轿厢宽度或x<0:
崩溃()
pygame.display.update()
时钟滴答(60)
博弈(循环)
pygame.quit()
退出

我在Youtube上使用了Sentdex的教程来教我一些关于pygame的知识,但我遇到了一个阻碍,导致我停止了进度,因为我正试图将这个游戏作为他的教程的扩展,而不仅仅是一个副本。

在windows上运行良好。我从中下载了一些随机的arcade字体文件。您的字体文件可能已损坏。还要注意的是,默认情况下,linux中以“.”开头的文件夹是隐藏的,但windows中不隐藏。那么,你能把字体文件放在其他文件夹中,然后试着运行这个代码吗?

我一回到家就得检查一下,我现在正在度假,不过谢谢你的提示!对非常感谢。
def car (x, y)
gameDisplay.blit (carImg, (x, y))

def text_objects (text, font):
textSurface = font.render (text, True, black)
return textSurface, textSurface.get_rect()

def message_display (text):
largeText = pygame.font.Font ("/Home/pi/.fonts/ARCADECLASSIC.TTF, 110)
Textsurf, TextRect-text_objects (text, largeText)
TextRect.center = ((display-width/2), (display-height/2))
gameDisplay.blit (TextSurf, TextRect)
import pygame
import time

pygame.init()

display_width=800
display_height=600

gameDisplay=pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Road Obstacles!")

black=(0,0,0)
white=(255,255,255)
red=(255,0,0)

car_width=50

clock=pygame.time.Clock()
carImg = pygame.image.load("Racecar.png")

def car(x,y):
    gameDisplay.blit(carImg,(x,y))

def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()

def message_display(text):
    largeText = pygame.font.Font("ARCADECLASSIC.TTF",110)
    TextSurf, TextRect = text_objects(text, largeText)
   TextRect.center = ((display_width/2),(display_height/2))
    gameDisplay.blit(TextSurf, TextRect)

    pygame.display.update

    time.sleep(2)

    game_loop

def crash():
    message_display("Woops! You Crashed!")



def game_loop():

    x = (display_width * 0.45)
    y = (display_height * 0.8)

    x_change = 0

    gameExit = False

    while not gameExit:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    x_change += -5
                elif event.key == pygame.K_RIGHT:
                    x_change += 5
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT:
                    x_change += 5
                if event.key == pygame.K_RIGHT:
                    x_change += -5


        x += x_change

        gameDisplay.fill(white)
        car(x,y)

        if x > display_width - car_width or x < 0:
            crash()

        pygame.display.update()
        clock.tick(60)

game_loop()
pygame.quit()
quit()