gpt4 book ai didi

java - 空指针异常Libgdx

转载 作者:行者123 更新时间:2023-12-02 05:12:13 29 4
gpt4 key购买 nike

我见过类似的问题,但没有一个与我在 Libgdx 项目(仅限桌面)中遇到的问题相符。我使用 Tiled 制作了一个 .tmx map ,并将其复制到 Assets 文件夹中,该文件夹有两个子包:gameScreens(带有 map )和图 block 。如果我使用 Tiled 从 Eclipse 打开 .tmx map ,它就可以正常工作。这是 .tmx:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="8" height="8" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="default" tilewidth="32" tileheight="32">
<tile id="0">
<image width="32" height="32" source="../tiles/rock.png"/>
</tile>
<tile id="1">
<image width="32" height="32" source="../tiles/tile_default_1.jpg"/>
</tile>
<tile id="2">
<image width="32" height="32" source="../tiles/tile_default_2.jpg"/>
</tile>
<tile id="3">
<image width="32" height="32" source="../tiles/wall.png"/>
</tile>
</tileset>
<layer name="Camada de Tiles 1" width="8" height="8">
<data encoding="base64" compression="gzip">
eJxjYWBgYCGAmXFgZHlGJHFGLPKU8okxH5f78GEAbrAA2Q==
</data>
</layer>
</map>

我创建了一个抽象类 GameState:

package com.mygdx.cavedive.game.GameStates;

//imports

public abstract class GameState {

private static TmxMapLoader mapLoader = new TmxMapLoader();
protected static OrthogonalTiledMapRenderer otmr;
protected static OrthographicCamera cam;

protected OrthogonalTiledMapRenderer getRenderer() {

return otmr;

}

protected TmxMapLoader getMapLoader() {

return mapLoader;

}

protected void disposeRenderer() {

otmr.dispose();

}

}

以及扩展它的类:

package com.mygdx.cavedive.game.GameStates;

//imports

public class Level_1 extends GameState implements Screen {

private TiledMap map;

@Override
public void render(float delta) {

//Clear the screen
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

otmr.setView(cam);

//Render the screen
otmr.render();

}

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

cam.viewportWidth = width;
cam.viewportHeight = height;
cam.update();

}

@Override
public void show() {

map = getMapLoader().load("gameScreens/level1.tmx");
otmr = new OrthogonalTiledMapRenderer(map, 1f / 32f);
cam = new OrthographicCamera();

}

@Override
public void hide() {

dispose();

}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {

disposeRenderer();
map.dispose();

}

}

现在这是我得到的:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.badlogic.gdx.maps.tiled.TmxMapLoader.loadTilesets(TmxMapLoader.java:246)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:118)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:104)
at com.mygdx.cavedive.game.GameStates.Level_1.show(Level_1.java:40)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.mygdx.cavedive.game.App.GameCore.create(GameCore.java:28)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

它与图 block 集有关,但我不知道是什么。

最佳答案

“图像集合”图 block 集(其中每个图 block 引用其自己的图像)是 Tiled 0.10 中的新功能。您使用的 libgdx 版本很可能还不支持此类图 block 集。

根据this issue on github ,libgdx nightlies 确实支持此功能。

关于java - 空指针异常Libgdx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27239949/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com