TmxMapLoader.load()上无效的文件路径 [英] Invalid Filepath on TmxMapLoader.load()

查看:109
本文介绍了TmxMapLoader.load()上无效的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注有关如何使用 LibGDX 制作android系统(可能不是,但我希望兼容性)的youtube教程,但遇到了从我的.tmx文件访问问题res文件夹.

I am following a youtube tutorial on how to make an android (probably not but I can hope for compatability) and iOS game using LibGDX and I have encountered a problem accessing a .tmx file from my res folder.

tileMap = new TmxMapLoader().load("res/level1.tmx");

使用上面的代码,我发现应用程序将在我的res文件夹中找到我的.tmx文件,但我必须向其提供有关如何查找在另一个选项卡中打开的文件的错误信息.这是两次按下shift调用的搜索方法的屏幕截图. http://imgur.com/PYd9Y5T

using the above code I figured that the application would find my .tmx file in my res folder but I must be giving it incorrect information on how to find a file I have open in another tab. here is a screenshot of the search method called by hitting shift twice. http://imgur.com/PYd9Y5T

我在搜索方法中看到了文件,但是无论我输入什么内容都找不到level1.tmx

I see the file in the search method, but no matter what I seem to type in I cannot find level1.tmx

 01-24 20:14:01.717  10013-10040/com.mac.elevator.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 60898
    Process: com.mac.elevator.android, PID: 10013
    com.badlogic.gdx.utils.SerializationException: Error parsing file: res/level1.tmx
            at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
            at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:92)
            at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:80)
            at com.mac.elevator.com.mac.elevator.states.Play.<init>(Play.java:91)
            at com.mac.elevator.handlers.GameStateManager.getState(GameStateManager.java:35)
            at com.mac.elevator.handlers.GameStateManager.pushState(GameStateManager.java:45)
            at com.mac.elevator.handlers.GameStateManager.<init>(GameStateManager.java:22)
            at com.mac.elevator.Game.create(Game.java:46)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1521)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1249)
     Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: res/level1.tmx (Internal)
            at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
            at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:163)
            at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:81)
            at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:92)
            at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:80)
            at com.mac.elevator.com.mac.elevator.states.Play.<init>(Play.java:91)
            at com.mac.elevator.handlers.GameStateManager.getState(GameStateManager.java:35)
            at com.mac.elevator.handlers.GameStateManager.pushState(GameStateManager.java:45)
            at com.mac.elevator.handlers.GameStateManager.<init>(GameStateManager.java:22)
            at com.mac.elevator.Game.create(Game.java:46)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1521)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1249)
     Caused by: java.io.FileNotFoundException: res/level1.tmx
            at android.content.res.AssetManager.openAsset(Native Method)
            at android.content.res.AssetManager.open(AssetManager.java:316)
            at android.content.res.AssetManager.open(AssetManager.java:290)
            at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)

推荐答案

测试一下,复制您的游戏资产,转到Android项目的文件夹,因为LibGDX是Wiki LibGDX的工作方式,谈论这个问题,但我不记得在哪里,尝试将.tmx文件放在文件夹中:

test this, copy the asset of your game, go to the folder of Android project, because that is how it works, LibGDX, is that the wiki LibGDX, talk about this but I do not remember where, try to put the file .tmx inside folder:

AndroidProyect->资产->地图-> yourmap.tmx.

AndroidProyect -> asset -> maps -> yourmap.tmx.

并尝试调用它:

tileMap = new TmxMapLoader().load("maps/level1.tmx");

在您的情况下,

资源应放在Asset Android项目文件夹中.而我们的代码将在项目完成的核心"中.

in your case, the, resources should go in the Asset Android project folder. While our code will be in the project completion "Core".

这篇关于TmxMapLoader.load()上无效的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆