Seamless scrolling tilemaps

﹥>﹥吖頭↗ 提交于 2020-06-27 15:33:11

问题


I'm working on a top-down rpg, and want to implement seamless scrolling maps. That is, as the player explores the world, there is no loading screen between maps and no "doors" to the next area.

I have two ways to break down the world. At the top level, I have "zones" which is simply a collection of 9 "maps"(These zones are only represented by directories). Within the zone, the 9 maps are organized into a 3x3 grid. I haven't figured out the best way to represent these maps yet, whether it's by index or by relative coordinate to it's parent zone. These maps are what actually get rendered to the user's screen. Given the size of each map, and the size of the viewport, I know that the user will only be able to see a max of four maps when they are on the corner of a map.

My problem is, how do I keep track of the maps and their respective offsets in code as the player explores the world? I was thinking about having a map<Point, Map*> with 0,0 being the map the player is current located in. If the player was on the bottom left corner of the map, then the map to the east would be stored in as 1,0, the map to the south would be 0,1 and the map southeast would be 1,1. The problem I foresee with this is, I'm not sure of the points are mutable, and if rebuilding the list every time the player moves into another map or a different section of the map would cause a problem.


回答1:


This is exactly like what I'm trying to do with a game I'm writing in FreeBASIC. What I'm doing is slightly different, but maybe it can be of some help.

I have a 1024^2 world map (so I can generate it fractally). Each land square on the world map is a REGION map (a miniature kingdom with a procedural history), but I made region maps very easy to generate. The region maps are 128^2 and I have four of them in a 256^2 array. When you get near the edge it moves the maps and creates 2-3 new regions (though it only makes ONE history-- the region the player is in).

Inside of these are 256^2 ZONE maps, which also tile 2x2 in a 512^2 array. Again, when approaching the edge it moves and generates new ones.

I tried a 3x3 grid some time ago, but had to reject it as inefficient.




回答2:


Consider a deque of deques. That way insertions and deletions on all 4 sides are easy.




回答3:


Well if you have a 3x3 pointer array of maps and you have 0,0 be the upper left, what you can do if you go into the room north of you, you can just do something like maps[1,1] = maps[1,0]; move each map down one and reload the top row.

Good luck! Hope you find an efficient solution!




回答4:


A suggestion: viewport.

I worked on a GPS device that defined a large area for drawing, but screen would only define a portion, or viewport, of the entire area. Scrolling involved moving the viewport (or changing the memory location for the display), and reloading the screen (using the graphics chip).

The concept is a like a 3x3 grid. The viewport starts in the center. Moving left, changes the address for the display memory.

Hope this helps.

BTW, this was an embedded system where the application could take 100% control of all the hardware devices (and not share with other applications).



来源:https://stackoverflow.com/questions/4061964/seamless-scrolling-tilemaps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!