SVG in game development for map drawing with map movement
I plan to draw a "map" (cities, rivers, roads, etc) using svg. So ALL object will be drawn in the one svg image, and only those that are inside of viewable area will be displayed (visible).
Question 1:
Is it reasonable approach? Or I would better care which particular objects are required to be drawn?
One of the feature I want to implement is to "drag" map. It is planned to work like following: user point mouse cursor somewhere inside the map, press mouse button and move mouse. So some objec开发者_开发百科ts will go out of the viewable area and others will be drawn.
Question 2:
Is it better to change coordinates of the visible object in order to shift them according to mouse movement? Or it is better to change "viewable area" (guess, that should be possible via viewbox svg-object parameters manipulation)?
Thanks a lot! Any ideas are welcome!
Sounds a bit like Polymaps to me. If you intended to serve a huge svg main document then the tiled polymaps approach is preferable.
I'm not a professional in any way nor am i a very good programmer but I've worked with svg maps before and I think it is a reasonable approach, svg's can hold alot of data and if you have a good renderer it should be able to keep up. As for question 2, I would say go with changing the view box, otherwise you will find yourself changing the coordinates of every svg object, lots of people have made panning code for an svg image so do a quick google search and that should help you.
The best approach would be greatly affected by how big and complex your single SVG would be.
You might want to create a quick experiment with a bigger, more complex sample map sooner rather than later, and rig it up to do simple panning (you could try svgpan before spending the time to craft your own). It wouldn't need to be a completely coherent map - you could repeat a bunch of representative shapes and still get a good test case.
If your sample map pans smoothly in the browsers you care about, you can avoid the complexity of tiling (or otherwise displaying portions of the whole).
If you find it jerky and slow, @Erik Dahlstrom's suggestion of looking at Polymaps would be the next place to look (but that involves a lot more server-side work so it would be nice to avoid).
精彩评论