Java chunk negative number problem
- by user1990950
I've got a tile based map, which is divided in chunks. I got a method, which puts tiles in this map and with positive numbers it's working. But when using negative numbers it wont work. This is my setTile method:
public static void setTile(int x, int y, Tile tile)
{
int chunkX = x / Chunk.CHUNK_SIZE, chunkY = y / Chunk.CHUNK_SIZE;
IntPair intPair = new IntPair(chunkX, chunkY);
world.put(intPair, new Chunk(chunkX, chunkY));
world.get(intPair).setTile(x - chunkX * Chunk.CHUNK_SIZE, y - chunkY * Chunk.CHUNK_SIZE, tile);
}
This is the setTile method in the chunk class (CHUNK_SIZE is a constant with the value 64):
public void setTile(int x, int y, Tile t)
{
if (x >= 0 && x < CHUNK_SIZE && y >= 0 && y < CHUNK_SIZE)
tiles[x][y] = t;
}
What's wrong with my code?