【问题标题】:When i make Android run file can't be read当我使 Android 运行文件无法读取时
【发布时间】:2020-05-16 09:10:56
【问题描述】:

您好,我在 LibGDX 中运行我的项目的 android 有问题,在桌面上运行一切正常。我在桌面上的工作目录位于“ProjecktGKLibGDX\android\assets”位置(与 android 默认值相同),当我在 android 应用程序中运行 projekt 时,它会因错误而崩溃,而不是找不到文件之一(menu.png )。我为 Sprites 使用 atlas,它的工作方式如下: atlas= new TextureAtlas("Menu.atlas"); 这是我的地图集文件:

menu.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
EXIT
  rotate: false
  xy: 1, 418
  size: 900, 415
  orig: 900, 415
  offset: 0, 0
  index: -1
LOAD
  rotate: false
  xy: 1, 1
  size: 900, 415
  orig: 900, 415
  offset: 0, 0
  index: -1

menu2.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
PLAY
  rotate: false
  xy: 1, 418
  size: 900, 415
  orig: 900, 415
  offset: 0, 0
  index: -1
SAVE
  rotate: false
  xy: 1, 1
  size: 900, 415
  orig: 900, 415
  offset: 0, 0
  index: -1

menu3.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
open_menu
  rotate: false
  xy: 1, 1
  size: 512, 512
  orig: 512, 512
  offset: 0, 0
  index: -1

Atlas 和 png 图像在同一个文件夹中(“ProjecktGKLibGDX\android\assets”),soo android 可以读取 Atlas 文件但无法读取 png 文件。

    com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: menu.PNG
        Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: menu.PNG (Internal)
        Caused by: java.io.FileNotFoundException: menu.PNG

【问题讨论】:

  • 为什么错误报告缺少menu. PNG 而不是menu. png
  • 我在不同的帖子中读到,android 可以像 PNG soo 一样读取它,在一次测试中我改变了这一点,但它与 PNG 和 png 一起工作我也尝试将名称“menu.atlas”更改为“ menu.pack”,然后在android运行,他找不到文件menu.pack,在桌面运行它总是工作
  • 注意信箱。在 Windows 上,即操作系统没有区别,并且会忽略字母大小写加载文件。但是在基于 linux 的系统上,作为 android 你必须匹配字母大小写。

标签: libgdx


【解决方案1】:

您的错误消息“读取文件时出错:menu.PNG(内部)”暗示它可能与使用 LibGDX 文件类型“内部”有关。如果您使用字符串创建 TextureAtlas,它会使用“内部”文件类型自动创建图集。 https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureAtlas.html#TextureAtlas-java.lang.String-

在桌面上,Internal 和 Local 文件类型基本上做同样的事情,所以这些并不重要,但在 Android 上它们是不同的。您可以在此处阅读有关不同文件类型的更多信息: https://github.com/libgdx/libgdx/wiki/File-handling

换行试试:

atlas= new TextureAtlas("Menu.atlas");

收件人:

atlas = new TextureAtlas(Gdx.files.local("Menu.atlas"));

【讨论】:

    【解决方案2】:

    可能是因为 menu.PNG 不存在。检查您的资产并确保您的文件名为“menu.PNG”。

    【讨论】:

      猜你喜欢
      • 2021-05-24
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 2020-02-27
      • 1970-01-01
      • 2016-02-22
      • 2019-02-11
      相关资源
      最近更新 更多