我目前正试图用slick2d库在java中编写一个小游戏。 问题是我的collission检测不起作用,因为getTileId返回错误的值。 这是我的init方法:
public void init(GameContainer arg0) throws SlickException {
grassMap = new TiledMap("data/grassmap.tmx");
blocked = new boolean[grassMap.getWidth()][grassMap.getHeight()];
player1 = new Player((int)x,(int)y,RADIUS);
for(int x = 1; x < grassMap.getHeight() ; x++) {
for(int y = 1; y < grassMap.getWidth() ; y++) {
int tileID = grassMap.getTileId(x, y, 0);
System.out.println(tileID);
String value = grassMap.getTileProperty(tileID, "blocked", "false");
if (value.equals("true"))
{
blocked[x][y] = true;
} else {
blocked[x][y] = false;
}
}
}
方法getTileId不知何故只返回2或22,我不知道为什么。
这是我的TiledMap:
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="10" height="10" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="grass" tilewidth="32" tileheight="32">
<properties>
<property name="blocked" value="false"/>
</properties>
<image source="grass.png" width="128" height="128"/>
</tileset>
<tileset firstgid="17" name="rocks" tilewidth="32" tileheight="32">
<properties>
<property name="blocked" value="true"/>
</properties>
<image source="rocks.png" width="128" height="128"/>
</tileset>
<layer name="Kachelebene 1" width="10" height="10">
<data encoding="base64" compression="gzip">
H4sIAAAAAAAACxNjYGAQIxIzEcDkqMNnD7o6dDPooY6a/iUGAwD5PKE9kAEAAA==
</data>
</layer>
</map>