pygame.error: font not initialized 如何修复?

所以我有这个错误 pygame.error: font not initialized 我已经厌倦了通过缩进它来修复它,未识别它,更改字体和其他东西但它仍然无法在我的 STARTMENUE 上工作。我也尝试过使用另一种字体,认为这是问题所在,但事实并非如此。

我有问题吗

largeText = pygame.font.Font('freesansblod.ttf',115)

我的完整代码

import pygame


#set screen

window = pygame.display.set_mode((500,500))


#set Name

pygame.display.set_caption("Noob")



class Player:

    def __init__(self,x,y,height,width,color):

        self.x = x

        self.y = y

        self.height = height

        self.color = color

        self.speed = 0

        self.isJump = False

        self.JumpCount = 10

        self.fall = 0

        self.rect = pygame.Rect(x,y,height,width)

    def draw(self):

        self.topleft = (self.x,self.y)


class Floor:

    def __init__ (self,x,y,height,width,color):

        self.x = x

        self.y = y

        self.height = height

        self.width = width

        self.color = color

        self.rect = pygame.Rect(x,y,height,width)

    def draw(self):

        self.topleft = (self.x,self.y)

        pygame.draw.rect(window,self.color,self.rect)



class Coin():

    def __init__(self,x,y,height,width,color):

        self.x = x

        self.y = y

        self.width = width

        self.height = height

        self.color = color

        self.rect = pygame.Rect(x,y,height,width)

    def draw(self):

        self.topleft = (self.x,self.y)

        self.draw.rect(self.color,self.rect)

    



white = (255,255,255)


green = (0,200,0)


red = (255,0,0)


drakred = (200,0,0)


darkgreen = (0,200,0)


black = (0,0,0)

 

player1 = Player(50,400,40,40,white)


coin = Coin(100,300,30,30,red)


floor1 = Floor(0,400,600,30,green)




fps = (30)


clock = pygame.time.Clock()



猛跑小猪
浏览 99回答 1
1回答

天涯尽头无女友

尝试在导入 pygame 的位置下方添加 pygame.font.init() 。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python