I'm trying to implement some collision detection to a test game i've been making. I've used TiledMap to create the map and set a property on one of the tiles to blocked=true This tile is then drawn on layer 0.
I then check to see if the tile exists in the direction the player is moving, using the following code
if (input.isKeyDown(Input.KEY_DOWN)) {
sprite = down;
sprite.update(delta);
int tileID = map.map.getTileId((int) x / map.map.getTileWidth(), (int) y / map.map.getTileHeight() + 1, 0);
String value = map.map.getTileProperty(tileID, "blocked", "false");
if (value.equals("true")) {
y += delta * 0.1f;
System.out.println("Tile ID: " + (int) (x / map.map.getTileWidth()) + ", " + (int) (y / map.map.getTileHeight() + 1) + " Try to walk down. Tile value below the player is:" + value);
}
}
This is repeated for each direction.
The problem I'm running into is it's picking up the blocked property for incorrect tiles You can understand better with this video. The yellow tiles are the collision/blocked tiles.