Reputation: 1
I'd like to ask for some assistance converting my 2d map imported from a text file into an isometric map format. I have browsed quite a bit, still kind of new to java and i am more of a "look at example code" rather than wriiting myself. ANYTHING would be helpful at this point. I have also looked here >> How can i convert x-y position to tile x-y for isometric tile? << and here >> Drawing Isometric game worlds << i feel like im almost there but i just quite figure it out. Thank you.
for(int row = rowOffset; row < rowOffset + numRowsToDraw; row++) {
if(row >= numRows) break;
for(int col = colOffset; col < colOffset + numColsToDraw; col++) {
if(col >= numCols) break;
if(map[row][col] == 0) continue;
int rc = map[row][col];
int r = rc / numTilesAcross;
int c = rc % numTilesAcross;
x = (col / Tile_H) + (row / Tile_W);
y = (row / Tile_W) - (col / Tile_H);
g.drawImage(
tiles[r][c].getImage(),
//(((y / Tile_HH) - (x / Tile_HW)) / 2) + col * tileSize,
//(((y / Tile_HH) + (x / Tile_HW)) / 2) + row * tileSize,
//x,
//y,
x + col * tileSize,
y + row * tileSize,
null
);
}
}
Upvotes: 0
Views: 847
Reputation: 287
Here's the formula to convert 2D coordinates in iso coordinates :
For [I,J] coordinates -> (carefull, I-J is something like this : 0, 1 and not raw coordinates(in pixel i mean).
I = (y - x) * (tileWidth / 2)
J = (x + y) * (tileHeight / 2)
Then you add 2 offsets(top and left to display the map in the center of the screen)
However I'm not sure if your problem was the formula, as I don't code in java.
Upvotes: 1