2011-06-30 121 views
7

我使用Python 2.6.6和pyglet 1.1.4。在我的“Erosion”文件夹中,我有“Erosion.py”和一个名为“Images”的文件夹。里面的图像,有.png图像。一个图像被命名为“Guard.png”。资源未找到pyglet异常

在 “Erosion.py” 有是去像这样的一段:我试图改变

pyglet.resource.path = ['Images'] 
pyglet.resource.reindex() 
self.image = pyglet.resource.image('%s%s' % (character, '.png')) 

当我运行此,我给

File "C:\Python26\lib\site-packages\pyglet\resource.py", line 394, in file raise ResourceNotFoundException(name) 
ResourceNotFoundException: Resource "Guard.png" was not found on the path. Ensure that the filename has the correct captialisation. 

指向['./Images']和['../Images']的路径。我也尝试删除路径和reindex调用,并将Erosion.py和Guard.png放在同一个文件夹中。

回答

0

尝试this

pyglet.image.load('path/to/image.png') 
+0

http://www.pyglet.org/doc/programming_guide/playing_sounds_and_music.html 更多关于加载资源 –

0

我得到这样使用pyglet和pyscripter(文本编辑器)中的问题。为了使文件被发现我有运行程序之前重新启动编辑器。

但是,这可能是pyscripter的问题。

+0

如果pyglet不允许直接指定完整路径名,这是pyglet中的一个问题。 –

2

这是我做的是能够加载的资源:

pyglet.resource.path = ['C:\\Users\\myname\\Downloads\\temp'] 
pyglet.resource.reindex() 

pic = pyglet.resource.image('1.jpg') 

texture = pic.get_texture() 
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) 

texture.width = 960 
texture.height = 720 

texture.blit(0, 0, 0) 
+0

也就是说,如果你真的需要它的资源处理程序。 我使用它,因为它使我可以通过GL库轻松快速地处理更多的附加参数。 – Torxed

+0

这太可怕了。当我打电话给“reindex()”时,我的电脑似乎索引了一切,需要几分钟时间。 –

+0

@BerryTsakala它旨在将所有补丁索引到您提供的补丁下面的文件夹中。因此,不要将您的脚本放在'\ Downloads \'并从那里索引,而是为您的项目使用特定的文件夹。 – Torxed

1

如果相对路径不工作,你可以使用os模块的绝对路径试试。

import pyglet 
import os 

working_dir = os.path.dirname(os.path.realpath(__file__)) 
pyglet.resource.path = [os.path.join(working_dir,'Images')] 
pyglet.resource.reindex() 

image = pyglet.resource.image('character.png')) 

最好使用os.path.join方法,而不是将其写为字符串以获得更好的跨平台支持。