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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Gayle

Pages: [1]
1
Python / Re: Help with drawing on RenderTexture
« on: July 12, 2015, 06:51:40 pm »
Hello,

I tried both examples and they work fine (you just forgot to load a font in the second one) on my side, as you can see on this image : https://monosnap.com/file/AEn0kRJDZ8itWCbUasdy04DtMt75L3.png.

Have you tried to use another font ? What version of python and pysfml are you using ?

Thanks for the help. I thought I'd read that a default font would be used if one wasn't provided. The example code does work once one is provided. My own code (the first bit) didn't work because I didn't pay attention to the documentation.

Quote from: 'pySfml Docs'
It is important to note that the Sprite instance doesn’t copy the texture that it uses, it only keeps a reference to it. Thus, an Texture must not be destroyed while it is used by an Sprite.

My code was in the __init__ method of an object (which I failed to mention), so it was destroyed as soon as the method finished. When draw was called on the sprite, the texture it had a reference to no longer existed. Using something like self.tex instead works.

2
Python / Help with drawing on RenderTexture
« on: July 12, 2015, 06:26:39 am »
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.

Pages: [1]
anything