I figured it out...
First of all, render
does not take positional arguments, so we can't use those.
Link to documentation:
my text won't blit to my display in pygame
Second, you have to specify the font to use.
I tried using this next:
import pygame
from pygame.locals import *
pygame.init()
font_game = pygame.font.SysFont("Arial",20)
t = pygame.font.Font.render(
"Testing: ",
1,
(255,255,255)
)
But this was erroring out
TypeError: descriptor 'render' for 'pygame.font.Font' objects doesn't
apply to a 'str' object
If you look at the documentation located here:
https://www.pygame.org/docs/ref/font.html#pygame.font.Font.render
These are the arguments:
render(text, antialias, color, background=None)
Background is an optional argument and I specified 3 arguments, so what did I do wrong?
When you install pygame
, one of the files that gets downloaded is the font.pyi
file.
If you look at that file, you have this:
class Font(object):
def __init__(self, name: Union[AnyPath, IO[Any], None], size: int) -> None: ...
def render(
self,
text: str,
antialias: bool,
color: _ColorValue,
background: Optional[_ColorValue] = None,
) -> Surface: ...
(There is more in that file, but that is the important part).
Not only do you have to specify the text, antialias, and color, but if you look at the first line in the class, def __init__
, that's where it's telling you that you need to specify the font and size.
Once I changed my code to this, it worked fine:
font_game = pygame.font.SysFont("Arial",20)
t = pygame.font.Font.render(
font_game,
"Testing: ",
1,
(255,255,255)
)