Java – what buffering strategy should I use for 2D scrolling maps?
So I'm creating a top - down 2D game in Java
I follow the instructions of Java 2D: hardware acceleration – Part 2 – buffer strategies to take advantage of hardware acceleration
Basically, what I'm thinking is: I want to be able to easily add more parts to the map So I'd rather not look at some of the suggested routes in the tutorials I've seen (each map block has an adjacent list of surrounding blocks; start with the center block and fill the screen with breadth first search)
Instead, my idea is to have a collection of tiles of screen size (for simplicity, for example, 32) × 32), and each screen "block" has a list referencing each adjacent set Then, I will create a buffer for the current screen and 8 adjacent screens, and draw the visible part in the VRAM buffer
My question is, is this the right way to solve this problem, or is there a better choice? I've seen a lot of tutorials, but they all seem to provide the same (seemingly high maintenance) options
This seems to be a better choice because it requires 1024 times the adjacency list to operate at the tile level In addition, the reason why I consider placing only the visible part in VRAM and leaving the "current" screen and its adjacent screens in the standard buffer is because I am a novice in hardware acceleration and am not completely sure how much space is acceptable and available Because Java tries to speed up standard buffers, should it theoretically be as fast as putting each buffer in VRAM?
Any and all suggestions are welcome!
Solution
I haven't seen any popular tile based game engines, but I consider using fly weight pattern to render only the blocks visible in the JScrollPane viewport JTable is both an example and a usable implementation
Appendix: one advantage of JTable method is view model separation, which allows people to transfer the acquisition of tile related resources to the model This makes it easier to optimize without changing the view
Even without a scroll bar, you can take advantage of scrollrecttovisible() by extending JComponent or an appropriate subclass The setdoublebuffered () method may also be useful