问题
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");
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
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)
回答1:
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 -> asset -> maps -> yourmap.tmx.
and try to call it:
tileMap = new TmxMapLoader().load("maps/level1.tmx");
in your case, the, resources should go in the Asset Android project folder. While our code will be in the project completion "Core".
来源:https://stackoverflow.com/questions/28132239/invalid-filepath-on-tmxmaploader-load