tobahhh
tobahhh

Reputation: 381

Loading a font from the system in pygame

I have a font called "pixelfont" that I would like to load onto my game. How can I load this font into pygame? I have tried the following method already:

    import pygame
    font_1_path = pygame.font.match_font("pixelfont", 0, 0)
    font_1 = pygame.font.Font(font_1_path, 128)
    text = font.render("Hello world!", True, (0, 0, 0))
    display.blit(text, [0, 0])

Why does this not print out "Hello world!" in pixelfont?

Upvotes: 3

Views: 841

Answers (1)

Anthony Pham
Anthony Pham

Reputation: 3106

You can use pixelfont.ttf instead of pixelfont if it is a .ttf file (font file) and it is in the same folder as your program. So use this instead after making sure the font file is in the same folder as your program:

font_1_path = pygame.font.match_font("pixelfont.ttf", 0, 0)

Upvotes: 2

Related Questions