# how to implement A Star path finding on 2D map with large tiles

The map tiles I have im my game are 64x64 pixels, and the characters are 16x16 pixels. I was reading about A Star path finding and I was wondering if I need my tiles closer to the size of my characters so that the movement given by the path finding seems more natural, or should I set up a different node map of where the characters can move, and use that in the A Star algorithm.

Or if you have a better solution let me know

Thanks!

EDIT: this is the Map class I am using

public class Map extends JComponent{
MapTile[][] map;
Random random;

public Map(char[][] mapKey){
map = createMap(mapKey);
}

public void update(){

}

@Override
public void paintComponent(Graphics g){
for(int i = 0; i < map.length; i++){
for(int j = 0; j < map[0].length; j++){
drawTile(g, map[i][j].getType(), i * 64, j * 64);
}
}
}

private MapTile[][] createMap(char[][] mapKey){
MapTile[][] temp = new MapTile[mapKey.length][mapKey[0].length];

for(int i = 0; i < mapKey.length; i++){
for(int j = 0; j < mapKey[i].length; j++){
temp[i][j] = new MapTile(mapKey[i][j]);
}
}
return temp;
}
}


really the only thing that the MapTiles hold at this point is a key to the Image they paint on the screen

• It depends very much on your movement style. If you have obstacles inside your tiles, you definitely need a finer graph so you can path around them. Feb 28, 2014 at 16:51
• Could you share a map sample? I understand you don't want characters to move in rigid lines. This can be corrected without changing the tiles. Feb 28, 2014 at 16:52
• Technically since we don't know what your map looks like I could only suggest that you combine a Navigation mesh aka navmesh for high level path-finding and use flow field to find the path between two neighbouring nodes. Using a naive implementation of A* will not get satisfactory results. You could try to lower the resolution but I fear this may increase memory consumption and/or reduce performance. Feb 28, 2014 at 19:47

Think of your character as moving from the centre of one tile to the next. You have to remember that A* works off a grid, and your grid determines the resolution of your movement.

If you have a 64x64 tile size, then you're going to be able to move at most in 64x64 increments. If visually this behavior isn't what you want, then consider resizing your grid for the A* purposes.

Remember that A* is an algorithm, a way to sort your data. Your data and your graphics CAN be different. If you take a 64x64 graphics tile, and separate it into 16 16x16 "path" tiles. That would allow you a single image for graphics, while having a higher pathfinding resolution.

• The only reason I wonder if I should resize my grid, is the number of times each map tile will draw, if I make all my tiles 16x16, then to make the same sized map I need to draw 16 times the number of tiles I am drawing now. I don't know enough about the graphics to know if this wall cause a problem Feb 28, 2014 at 20:26