【问题标题】:Python Cocos2d can't find resource image after resizing itPython Cocos2d 调整大小后找不到资源图像
【发布时间】:2018-11-28 10:23:09
【问题描述】:

我正在尝试在 Python 中调整图像的大小,然后使用调整后的图像加载 cocos2d 精灵。但是,尝试初始化 cocos2d sprite 会导致找不到资源的错误。重现问题的示例代码:

from pathlib import Path
import cocos
from PIL import Image

im = Image.open("in.jpg")
im.thumbnail((600, 900))
im.save("out.jpg", "JPEG")
im.close()

file = Path("out.jpg")
if file.is_file():
    print("File exists")

sprite = cocos.sprite.Sprite("out.jpg")

这会导致错误 pyglet.resource.ResourceNotFoundException: Resource "out.jpg" was not found on the path. Ensure that the filename has the correct captialisation.

但是,输出是:

File exists

第二次运行它不会出错,因为out.jpg 已在上一次运行中创建。删除out.jpg 并再次运行它会产生错误。

添加im.close() 并没有解决问题。

操作系统为 Windows 10,Python 版本为 3.6.4。

【问题讨论】:

  • 看来问题出在pyglet.resource.image(image),它在Cocos框架中加载了图片

标签: python python-3.x cocos2d-python


【解决方案1】:

原来是pyglet中用来加载资源的方法。我不得不重新索引图像。动态添加的图像目录中的文件和 pyglet 创建现有图像的索引。答案见https://stackoverflow.com/a/16438410/6350693

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 2016-11-30
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    相关资源
    最近更新 更多