Greetings!
I'm working on a game using PySFML, I'm trying to change the font of a sf.String variable but python.exe stops working without an error message.
Here is what I've written:
font = sf.Font()
font.LoadFromFile('my_downloaded_font.ttf', 50)
self.welcomemsg = sf.String("Welcome, "+self.lastplayer, font)
Thanks for any help.
UPDATE: I almost forget it, I'm using IDLE (python 2.7), Windows 7 and PySFML 1.6
UPDATE: Everything's OK when I do this:
font = sf.Font()
font = sf.Font.GetDefaultFont()
#font.LoadFromFile('my_downloaded_font.ttf', 50)
self.welcomemsg = sf.String("Welcome, "+self.lastplayer, font)
Before someone says it. I know its an old topic about this exact same quest but replies were just like change to version 2.0 which I can't do.
Any real solution to the problem?
You have to instantiate sfml.Font using sfml.Font.load_from_file (bastie leonard bindings, though) or sfml.Font.get_default_font
So:
# incorrect
font = sfml.Font()
font = sfml.Font.get_default_font()
# correct
font = sfml.Font.get_default_font()
If you are thinking on using sfml2-python2 (Sonkun bindings, of course), please take a look on the documentation http://python-sfml.org/api/graphics.html#font and http://python-sfml.org/api/graphics.html#text
font = sfml.Font.get_default_font()
I'm guessing you are using sfml because you did from PySFML import sf as sfml
. If that is the case I already tried that and it says Font has no attribute 'load_from_file', same thing with get_default_font.