Basically i'm trying to draw to a RenderTexture and then use that texture in a sprite. But I can't get it to work.
txt = sf.Text('This is a test!')
txt.color = sf.Color.RED
txt.font = sf.Font.from_file('ProggyCleanSZ.ttf')
tex = sf.RenderTexture(200,200)
tex.clear(sf.Color.BLACK)
tex.draw(txt)
tex.display()
self.sprite.texture = tex.texture
The sprite is then drawn to the screen. The sprite shows up as a white box with no text, even though it was cleared with black. If I draw the text to the screen directly, there is no problem.
Even copying and pasting the example code from the documention doesn't work.
# create a new render-window
window = sf.RenderWindow(sf.VideoMode(800, 600), "pySFML - RenderWindow")
# create a new render-texture
texture = sf.RenderTexture(500, 500) #The example says RenderTexture.create(500,500) but that method doesn't exist.
# the main loop
while window.is_open:
# ...
# clear the whole texture with red color
texture.clear(sf.Color.RED)
# draw stuff to the texture
text = sf.Text('Teenage Mutant Ninja Turtles')
texture.draw(text)
# we're done drawing to the texture
texture.display()
# now we start rendering to the window, clear it first
window.clear()
# draw the texture
sprite = sf.Sprite(texture.texture)
window.draw(sprite)
# end the current frame and display its content on screen
window.display()
This results in a red box on a black background and no text. No clue why this one actually clears with the right color.
I'm completely lost.