java—我在线程“lwjgl application”com.badlogic.gdx.utils.serializationexception中发现异常:解析文件mar.tmx时出错

eqfvzcg8  于 2021-07-06  发布在  Java
关注(0)|答案(8)|浏览(264)
Hi I'm trying to add tiled map but all time I'm getting the same error: 

"Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: mar.tmx
    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
    at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:70)
    at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:59)"

我看到一个类似的帖子,有人说我的Map有错误的格式,但我尝试了每一种格式,仍然是一样的。调试之后,我得到map=null。有人知道它为什么不起作用吗?lll

iqxoj9l9

iqxoj9l97#


package Screens;

    import Scenes.Hud;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.Screen;
    import com.badlogic.gdx.graphics.GL20;
    import com.badlogic.gdx.graphics.OrthographicCamera;
    import com.badlogic.gdx.maps.tiled.TiledMap;
    import com.badlogic.gdx.maps.tiled.TmxMapLoader;
    import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
    import com.badlogic.gdx.utils.viewport.FitViewport;
    import com.badlogic.gdx.utils.viewport.Viewport;
    import com.mygdx.game.Marioxx;

    public class PlayScreen implements Screen
    {
        private com.mygdx.game.Marioxx game;

        private OrthographicCamera gamecam;
        private Viewport gamePort;
        //Tiled map variables
        private TmxMapLoader maploader;
        public TiledMap map;
        private OrthogonalTiledMapRenderer renderer;

        private Hud hud;

        public PlayScreen(com.mygdx.game.Marioxx game)
        {
            this.game = game;
            gamecam = new OrthographicCamera();
            gamePort = new FitViewport(Marioxx.V_WIDTH, Marioxx.V_HEIGHT, gamecam);
            hud = new Hud(game.batch);

            maploader = new TmxMapLoader();
            map = maploader.load("mar.tmx");
            renderer = new OrthogonalTiledMapRenderer(map);
            gamecam.position.set(gamePort.getScreenWidth()/2, gamePort.getScreenHeight()/2, 0);
        }

        @Override
        public void show()
        {

        }

        @Override
        public void render(float delta)
        {
            Gdx.gl.glClearColor(1,0,0,1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
            hud.stage.draw();

            renderer.render();

        }
        public void handleInput(float dt )
        {

            if(Gdx.input.isTouched())
            {
                gamecam.position.x += 100* dt;

            }

        }

        public void update(float dt)
        {

             handleInput(dt);

             gamecam.update();

             renderer.setView(gamecam);

        }

        @Override
        public void resize(int width, int height)
        {

            gamePort.update(width, height);

        }

        @Override
        public void pause() {

        }

        @Override
        public void resume() {

        }

        @Override
        public void hide() {

        }

        @Override
        public void dispose() {

            map.dispose();
            renderer.dispose();

        }
    }

相关问题