Question:
Can somebody give me a font I can use in replit!!!
Current behavior:
It won’t let me use a font.
Desired behavior
I want to use a font.
Repl link:
https://replit.com/@StevenBrixie/space-shooter-2
font = pygame.font.Font('', 20)
Question:
Can somebody give me a font I can use in replit!!!
Current behavior:
It won’t let me use a font.
Desired behavior
I want to use a font.
Repl link:
https://replit.com/@StevenBrixie/space-shooter-2
font = pygame.font.Font('', 20)
not many are built-in. You could use the built-in ones, using pygame.font.SysFont
or upload a font into your repl’s files, and reference that file using pygame.font.Font
as you are.
Run in Shell to get the installed fonts on replit:
fc-list : family
DejaVu Sans Mono
DejaVu Sans
DejaVu Serif
Available fonts are listed with pygame.font.get_fonts()
. These fonts are usable with pygame.font.SysFont
. Note that pygame.font.SysFont
will default to the pygame font if the given font is not found.
print(pygame.font.get_fonts())
# ['dejavuserif', 'dejavusansmono', 'dejavusans']
font = pygame.font.SysFont('dejavuserif', 20)
print(font.name) # 'DejaVu Serif'
pygame.font.Font
is for font files. But if you just need any font then you can use the default font by passing in None
instead of a file path, which is what I typically use (not system specific).
font = pygame.font.Font(None, 20)
Also, the pygame.freetype
module has all of the stuff that pygame.font
does but with more features, so I’d recommend using that.
Thank you for your help!
You have to do pygame.font.init() on the line before the font.