Cannot draw () sprites in a piglet

For some reason, I can't get pyglet to draw sprites. Here is my code:

import pyglet game = pyglet.window.Window(640, 480, "I'm a window") batch = pyglet.graphics.Batch() pyglet.resource.path = ["."] pyglet.resource.reindex() image = pyglet.resource.image("hextile.png") pyglet.sprite.Sprite(image, x=200, y=300, batch=batch) pyglet.text.Label('DING', font_name='Arial', font_size=24, x=100, y=100, batch=batch) @game.event def on_draw(): game.clear() batch.draw() #image.blit(0, 0) pyglet.app.run() 

Now, when I draw the package, the text label is displayed correctly. I see "DING" on the window. However, the image "hextile.png" is not displayed. I tried to draw the sprite myself, but that didn't work either. However, the sparkle of the image (as shown in the commented line) seems to work very well, but it’s obvious that the functionality that I am here is not quite. I can not understand this. What am I missing?

+4
source share
2 answers

Assuming you and your friends have ATI graphics cards:

Sprite.draw () uses the v2i format and VertexDomain.draw () internally. For some reason, this combination does not work on drivers of Windows Vista / 7 Catalyst 11.9 and higher, and therefore also unable to complete the drawing Sprite. See Also: Piglet vertex list not displayed (AMD driver?)

There is a piglet problem you might want: http://code.google.com/p/pyglet/issues/detail?id=544

Your options currently look either to fix pyglet.sprite.Sprite, as mentioned in the third comment on this issue or downgrading your video driver.

Update: No need to fix Sprite or downgrade your video driver. This issue seems to be fixed with Catalyst 12.4 (video driver 8.961.0.0).

+5
source

Sprite receives garbage collection because you do not keep a link to it. Do it:

 sprite = pyglet.sprite.Sprite(image, x=200, y=300, batch=batch) 

For what it's worth, I prefer to use a subclass of Window, for example: (this code also works for me)

 import pyglet class Window(pyglet.window.Window): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.batch = pyglet.graphics.Batch() image = pyglet.resource.image('hextile.png') self.sprite = pyglet.sprite.Sprite(image, batch=self.batch) def on_draw(self): self.clear() self.batch.draw() def main(): window = Window(width=640, height=480, caption='Pyglet') pyglet.app.run() if __name__ == '__main__': main() 
+1
source

Source: https://habr.com/ru/post/1401271/


All Articles