Map 平铺贴图对象大小

Map 平铺贴图对象大小,map,properties,libgdx,tiled,Map,Properties,Libgdx,Tiled,我正在通过TmxMapLoader加载平铺贴图,我在获取平铺等方面没有问题。但当我想从对象层提取值时,我只能通过以下代码获取x,y: MapProperties props = layer.getObjects().get(i).getProperties(); float x = (float) props.get("x"); float y = (float) props.get("y"); RectangleMapObject rect = (RectangleMapObject) la

我正在通过TmxMapLoader加载平铺贴图,我在获取平铺等方面没有问题。但当我想从对象层提取值时,我只能通过以下代码获取x,y:

MapProperties props = layer.getObjects().get(i).getProperties();
float x = (float) props.get("x");
float y = (float) props.get("y");
RectangleMapObject rect = (RectangleMapObject) layer.getObjects().get(i);
float x = (float) rect.getRectangle().x;
float y = (float) rect.getRectangle().y;
float width = rect.getRectangle().width;
float height = rect.getRectangle().height;
这让我得到了正确的值,但当我尝试添加以下内容时:

float width = (float) props.get("width");
float height = (float) props.get("height");
这给我带来了一个错误:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at cz.vilix.managers.MapManager.<init>(MapManager.java:67)
at cz.vilix.main.Game.create(Game.java:50)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

打印:
null-null

有效的解决方案是获取RectangleMapObject(或任何其他形状),然后使用以下代码获取基本矩形:
矩形r=rect.getRectangle()
,并且可以使用矩形的参数

或者,您可以跳过创建新矩形对象的步骤,并在以下代码中使用它:

MapProperties props = layer.getObjects().get(i).getProperties();
float x = (float) props.get("x");
float y = (float) props.get("y");
RectangleMapObject rect = (RectangleMapObject) layer.getObjects().get(i);
float x = (float) rect.getRectangle().x;
float y = (float) rect.getRectangle().y;
float width = rect.getRectangle().width;
float height = rect.getRectangle().height;