资源索引:找不到资源

时间:2018-06-14 13:20:05

标签: python pyglet

我正在阅读Python Pyglet模块文档(found here),教自己如何使用它,更具体地说,是Asteroids游戏示例,但我似乎无法获得任何类型的资源索引工作。我试过了:

pyglet.resource.path = ['resources']
pyglet.resource.reindex()

正如示例所示,以及仅仅定义路径并将其与 -

一起使用
path = '/users/...../Documents/Python Game Example/resources/'
...
pyglet.image.load(path + 'ship.png')

(其中列出了有效路径)

但是,唉,无济于事。根据我的理解(相当缺乏诚实),似乎程序根本没有重新索引资源路径,因为我在运行代码时得到的错误:

    Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/resource.py", line 435, in file
    location = self._index[name]
KeyError: 'ship.png'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/...../Documents/Python Game Example/Asteroids Version I/Asteroids.py", line 6, in <module>
    player_image = resource.image('ship.png')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/resource.py", line 555, in image
    atlas=atlas)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/resource.py", line 482, in _alloc_image
    file = self.file(name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/resource.py", line 438, in file
    raise ResourceNotFoundException(name)
pyglet.resource.ResourceNotFoundException: Resource "ship.png" was not found on the path.  Ensure that the filename has the correct captialisation.

经过大量的在线搜索,我找不到任何解决方案,我不知道如何解决这个问题。我需要的只是pyglet.resource.reindex()实际工作,但正如我所说,从我的理解,它根本不是?

0 个答案:

没有答案