The main thing I wanted to mention since you say you’re working with Java has to do with this bit of your parser:
Integer.parseInt(tokens[col]) may throw an exception if you decide to use the tile flipping feature in Tiled, since the value that is saved would be an unsigned int, which Java doesn’t exactly support.
From Java’s documentation:
parseInt(String s)
Parses the string argument as a signed decimal integer.
The main difference between signed and unsigned integers is that they use the same number of bits to define a different range of numbers; signed ints being able to represent negative numbers. The exception might occur because the value would appear to be out of range for a signed value.
If you wish to support tile flipping in Java you will want to use this in your parser instead:
map[row][col] = Long.valueOf(tokens[col]).intValue();
The max value of a Long in Java is incidentally the max value of an unsigned int, so you will be able to read in the value correctly. Do note that intValue()
may appear negative if a large value was parsed but it would still be correct to use in this instance.
To handle negative id’s you’ll need to add the following constants:
// Bits on the far end of the 32-bit global tile ID are used for tile flags
static final int FLIPPED_HORIZONTALLY_FLAG = 0x80000000;
static final int FLIPPED_VERTICALLY_FLAG = 0x40000000;
static final int FLIPPED_DIAGONALLY_FLAG = 0x20000000;
And perform the following operation to get the proper ID:
int rc = map[row][col];
// Clear the flags
rc = rc & ~(FLIPPED_HORIZONTALLY_FLAG |
FLIPPED_VERTICALLY_FLAG |
FLIPPED_DIAGONALLY_FLAG);
You may also define a few booleans for readability:
boolean flipHorizontal = (rc & FLIPPED_HORIZONTALLY_FLAG) != 0;
boolean flipVertical = (rc & FLIPPED_VERTICALLY_FLAG) != 0;
boolean flipDiagonal = (rc & FLIPPED_DIAGONALLY_FLAG) != 0;
You’ll still need to get the appropriate tileset info to subtract the first GId, but that should cover some of the quirkiness with Java.
You’re good! I apologize for my much later wall of text, but I do enjoy talking about Java 