简体   繁体   English

Pyglet:Sprite.draw()和Batch.draw()不起作用,但是Image.blit起作用

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

In pyglet, which I'm learning, Image.blit() works, but Sprite.draw() doesn't, nor Batch.draw(), even in this simple code: 在我正在学习的pyglet中,Image.blit()可以工作,但Sprite.draw()不能,或者Batch.draw()也不起作用,即使在以下简单代码中:

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. 我发现的唯一解释是关于图形卡和其中的一些“ v2i”错误的,但是我担心在不真正了解我在做什么的情况下接触pyglet的代码。

The third answer of this thread worked for me, even though I'm using Ubuntu and not Windows. 即使我使用Ubuntu而不是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. 我在/usr/lib/pymodules/python2.7/pyglet/sprite.py找到的文件中的“ v2i”中的第368和372行处,用“ f”替换了“ i”。 Then I saved, ran my code, and everything was working. 然后我保存,运行我的代码,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM