I’m making a map editor for my 2d tile based RPG game, and I’m running into a roadblock. The problem is actually how to draw the grid lines efficiently for large maps like, say 300x300 tiles. I mean the actual grid LINES, not the map tiles.
Originally I called redrew the entire grid line by line every time you moved the mouse or clicked(since it allows you to drag and also highlights the tile you are hovering over). This was horrible for large maps and was VERY slow. So my solution was to create a bufferedImage for the grid of a specified size right when a new empty map was created, and redraw that image every time paint was called. This worked well, except that for anything above 200x200ish java would run out of heap space in creating that bufferedImage. I can’t really have a preloaded image because the user should be able to specify a new map to be any size. Also, I like the grid to be drawn over the tiles, otherwise the tiles cover up the lines and it looks messier. That means the grid has to be drawn again every time tiles are added right?
Is there another way to draw a very large grid that will repaint each time you move the mouse? The program Tiled can easily create maps of 1000x1000 or more, how is it done?? Thanks