Java chunk negative number problem

Posted by user1990950 on Game Development See other posts from Game Development or by user1990950
Published on 2013-10-17T10:27:44Z Indexed on 2013/10/17 16:26 UTC
Read the original article Hit count: 235

Filed under:
|

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?

© Game Development or respective owner

Related posts about java

Related posts about math