Reuse Font objects multiple times
nthykier opened this issue · 0 comments
nthykier commented
You mentioned in pygame/pygame#673 that the game is using a lot of CPU rendering the text. I suspect (but have not profiled the game) that you can gain a considerable performance by avoiding the reloading of the Fonts for each word rendered.
I.e.
word_surface = pygame.font.Font(
None, 36).render(wordText, 1, color)
Would be replaced with:
# in __init__
[...]
self.font = pygame.font.Font(None, 36)
# in renderWord
word_surface = self.font.render(wordText, 1, color)
Another approach that might work in this particular game would be to cache the rendered words (clearing the cache when self.text
is reset).