I'm trying to make a function to check if a cell in Tiled can be passed, by accessing a Boolean custom property I gave each tile. This is (part of) my code.
...
public boolean isCellPassable(int column, int row, MapLayer layer) {
boolean canPass = Boolean.valueOf((Boolean) ((TiledMapTileLayer) layer).getCell(column, row).getTile().getProperties().get("can_pass"));
if (canPass == true) {
return true;
}
else {
return false;
}
}
public void displayHUD(ShapeRenderer hud) {
System.out.println(isCellPassable(0, 6, Main.level1.getLayers().get("base")));
...
And even though in the isCellPassable
function I cast it to a Boolean, for some reason I still get this error ..
Exception in thread "LWJGL Application" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
.. on the line where I set the value of canPass
.
您可能应该删除对Boolean
的Boolean.valueOf(String)
,并确保选择了Boolean.valueOf(String)
重载。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.