Hi,
I once had an error like that as well. It turned out that it worked fine if I set the font = None in the class before def __init__ I dont know if this is something similar, but I am attaching the code to my Text class if it helps any.
Good luck squashing bugs :)
Spot.
Hi. I just recently noticed that I keep getting this error on a game that I am making:
Traceback (most recent call last): File "main.py", line 176, in ? main() File "main.py", line 141, in main runGame() File "main.py", line 80, in runGame endState = currentLevel.run() File "/home/therat/Desktop/bibledave_v0.6.4.3/basegamelevel.py", line 649, in run self.hud.paint(self.screen) File "/home/therat/Desktop/bibledave_v0.6.4.3/hud.py", line 81, in paint base.drawTextColored (surface, 24, draw_text, (w/8, (h-h/4) + (line_num - min) * 30), (self.drawTextColor, self.drawTextColor, self.drawTextColor)) File "/home/therat/Desktop/bibledave_v0.6.4.3/base.py", line 113, in drawTextColored orig = font.render(message, 0, fontcolor) pygame.error: SDL_ttf render failed
When text is displayed on the hud it is supposed to fade out but the game crashes and displays this error instead. I have no idea how this happened because the game used to work fine one day and the next it began to crash.
One other issue I have noticed is that pygame.init() takes forever to load (whether solar wolf or some of the pygame demos).
Any ideas? Thanks, Joe -- All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2
import pygame
#Text class
class Text:
font = None
def __init__(self, text, position, color, font, font_size, center_or_origin):
self.text = text
self.position = position
self.color = color
#self.shadow_color = shadow_color
self.font = font
self.fontsize = font_size
# set position to be middle of text
#weird bug in idle:
# if you have #set on a line and have no space before set,
# it highlights to not be a comment. script works, but no highlight
self.font = pygame.font.Font(self.font, self.fontsize)
#print self.text
self.width, self.height = self.font.size(self.text)
self.image = self.font.render(self.text, 1, self.color)
#self.rect = (position, (self.width, self.height))
if center_or_origin == 1:
self.rect = self.image.get_rect(topleft=position)
elif center_or_origin == 0:
self.rect = self.image.get_rect(center=position)