Pyglet: Sprite.draw() and Batch.draw() don't work, but Image.blit does

点点圈 提交于 2019-12-13 04:58:28

问题


In pyglet, which I'm learning, Image.blit() works, but Sprite.draw() doesn't, nor Batch.draw(), even in this simple code:

import pyglet

win = pyglet.window.Window()

img = pyglet.resource.image('test.png')
spr = pyglet.sprite.Sprite(img)

@win.event
def on_draw():
    win.clear()
    spr.draw()


if __name__ == '__main__':
    pyglet.app.run()

The window remains black. However, I can draw labels, for example. THe only explaination I found was about graphic cards and "v2i" bugs with some of them, but I'm afraid to touch at pyglet's code without really knowing what I'm doing.


回答1:


The third answer of this thread worked for me, even though I'm using Ubuntu and not Windows. It's actually a hardware problem. I replaced the "i" with the "f" at lines 368 and 372 in "v2i" in a file I found at /usr/lib/pymodules/python2.7/pyglet/sprite.py. Then I saved, ran my code, and everything was working.



来源:https://stackoverflow.com/questions/10266799/pyglet-sprite-draw-and-batch-draw-dont-work-but-image-blit-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!