SFML community forums

Bindings - other languages => Python => Topic started by: nbermudez on January 28, 2013, 10:28:29 pm

Title: LoadFromFile crashes without error.
Post by: nbermudez on January 28, 2013, 10:28:29 pm
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)
Title: Re: LoadFromFile crashes without error.
Post by: nbermudez on January 29, 2013, 10:48:23 pm
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?
Title: Re: LoadFromFile crashes without error.
Post by: shackra on January 31, 2013, 02:28:32 am
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
Title: Re: LoadFromFile crashes without error.
Post by: nbermudez on February 02, 2013, 01:42:05 am
Quote
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.
Title: Re: LoadFromFile crashes without error.
Post by: shackra on February 02, 2013, 03:32:24 am
are you using sfml 1.6 or 2.0?  ???
Title: Re: LoadFromFile crashes without error.
Post by: nbermudez on February 02, 2013, 04:49:57 pm
PySFML 1.6
I had some modules already implemented in 1.6 and no time to rewrite it for 2.0  :(
Title: Re: LoadFromFile crashes without error.
Post by: shackra on February 02, 2013, 07:15:00 pm
PySFML 1.6
I had some modules already implemented in 1.6 and no time to rewrite it for 2.0  :(

Better move your code to 2.0, there is a obvious difference between 1.6 and 2.0's API . Also, 2.0 have several bug fixes...