0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Magus Feb 28 '14 at 16:51
  • \$\begingroup\$ 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. \$\endgroup\$ – wolfdawn Feb 28 '14 at 16:52
  • \$\begingroup\$ 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. \$\endgroup\$ – wolfdawn Feb 28 '14 at 19:47
0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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 \$\endgroup\$ – Joseph Dour Feb 28 '14 at 20:26
  • \$\begingroup\$ I updated the answer addressing these concerns. \$\endgroup\$ – Thebluefish Feb 28 '14 at 20:36
  • \$\begingroup\$ I thought A* works off of nodes, not grids. It just so happens that a grid cell can be represented by a grid. \$\endgroup\$ – Lysol Feb 28 '14 at 22:50
  • \$\begingroup\$ It does, that's why I mentioned he may use the centre of the tiles as an example. The main point of my answer is to explain that his graphics and his data representation don't have to match 1:1. \$\endgroup\$ – Thebluefish Feb 28 '14 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.