SFML community forums

Bindings - other languages => Python => Topic started by: Nya-chan Production on May 30, 2011, 04:17:48 pm

Title: PySFML 1.6 + Python 2.7 cannot load font?
Post by: Nya-chan Production on May 30, 2011, 04:17:48 pm
Got a weird error on Win7, while trying to import font to my game via this class:

Code: [Select]
class StartText(GameText):

    def Create(self, text, xpos, ypos, active):
        font = sf.Font()
        font.LoadFromFile('Arial.ttf')
        self.active = active
        if self.active == False:
            self.text = sf.String(text, font, Size = 10)
        else:
            self.text = sf.String(text, font, Size = 12)
            self.text.Italic
        self.text.SetColor(sf.Color(0, 0, 0))
        self.text.SetPosition(xpos, ypos)


On suggestion from IRC I simplified it to this in a separate file:

Code: [Select]
from PySFML import sf
font = sf.Font()
print 1
font.LoadFromFile(" Arial.ttf ")
print 2


This prints 1 and then crashes without an error, python just stops working. In both cases Arial.ttf is in the same folder as the script and is correctly capitalized. Anyone else experienced this or knows how to fix it? ^^
Title: Re: PySFML 1.6 + Python 2.7 cannot load font?
Post by: Chèvre on May 31, 2011, 05:09:00 pm
Your method looks correct. Back when I used SFML 1.6, I used to load fonts like you did in the second example.

However, those extra spaces around 'Arial.ttf' seem weird to me.

And you say that Python crashes "without an error" -- as in nothing appears in the console window? Are you running Python from the command line?

If it still doesn't work, then maybe your Arial.ttf file is faulty somehow?

Also, if you're starting a new project, I'd recommand using the new SFML 2 binding: https://github.com/bastienleonard/pysfml2-cython
Title: Got the same problem
Post by: andreaszdw on June 14, 2011, 09:24:48 am
Hello,

I have the same problem, runs fine under Linux and XP, but not
under Vista.

Can someone tell me, when SFML 2 is released?

Andreas
Title: Re: Got the same problem
Post by: Nexus on June 14, 2011, 10:36:34 am
Quote from: "andreaszdw"
Can someone tell me, when SFML 2 is released?
No (http://www.sfml-dev.org/forum/viewtopic.php?t=5014) ;)

But you can already use the Git version now.
Title: How use Git version
Post by: andreaszdw on June 14, 2011, 02:29:22 pm
Hello,

can anyone tell me, how I can use the Git version?

Andreas
Title: PySFML 1.6 + Python 2.7 cannot load font?
Post by: Laurent on June 14, 2011, 02:53:18 pm
Use a Git client (TortoiseGit on Windows) to get the source directly from the repository, or download a snapshot from the download page of the website. Then follow the tutorial (the only one for 2.0) to compile SFML.