Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Text doesn't show up (pysfml-cython)  (Read 4756 times)

0 Members and 1 Guest are viewing this topic.

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
[Solved] Text doesn't show up (pysfml-cython)
« on: April 24, 2012, 04:54:52 am »
Hello! :D

I finally can build PySFML :), so, I started playing with it, but Oh Lord!, I can't make appears a simple text in the game window, here is the code:
Code: [Select]
#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sfml

window = sfml.RenderWindow(sfml.VideoMode(640, 480),
                           "Dibujando una imagen en SFML")
window.framerate_limit = 60
running = True
texture = sfml.Texture.load_from_file("mog.png")
sprite = sfml.Sprite(texture)
letra = sfml.Font()
print letra.DEFAULT_FONT
texto = sfml.Text("Hola mundo!", letra, 50)
texto.color = sfml.Color.BLACK
print texto.string

while running:
    for event in window.iter_events():
        if event.type == sfml.Event.CLOSED:
            running = False
        if event.type == sfml.Event.KEY_PRESSED:
            if sfml.Keyboard.is_key_pressed(sfml.Keyboard.W):
                sprite.y -= 10
            if sfml.Keyboard.is_key_pressed(sfml.Keyboard.S):
                sprite.y += 10
            if sfml.Keyboard.is_key_pressed(sfml.Keyboard.A):
                sprite.x -= 10
            if sfml.Keyboard.is_key_pressed(sfml.Keyboard.D):
                sprite.x += 10

    window.clear(sfml.Color.WHITE)
    window.draw(sprite)
    window.draw(texto)
    window.display()

window.close()

what I'm doing wrong?
« Last Edit: November 04, 2013, 10:18:19 am by Sonkun »

GNU User
Python programmer
Blog

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Re: Text doesn't show up
« Reply #1 on: April 24, 2012, 12:17:02 pm »
It's because you use an “empty” font object. The same thing happens with C++ SFML.
If you don't specify a font at all, specify the default font (sfml.Font.DEFAULT_FONT), or load one of your fonts with the class method sfml.Font.load_from_file(), it should work.

I'm going to make the constructor raise an exception like for other classes that use class methods instead of the constructor for creating objects.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: Text doesn't show up
« Reply #2 on: April 25, 2012, 02:42:37 am »
huh, I see... so, I should do letra = sfml.Font.load_from_file("sometypography.ttf") instead of what I am doing!
and yes, it works now :)

thanks!

GNU User
Python programmer
Blog

 

anything