0

I'm trying to create a tile based world map like Tribal Wars has or The-West games. I created a little bit of it but it loads too slow when you drag the map with your mouse.

My algorithm works like this:


On page load:

  • load the tiles from 1 to 19(x1 to y1 and x2 to y2) via JQuery's $.post method(I need the screen's width and height for that 19=1900/tile_width, because I want the map to fill the entire page)
  • append the returned data(tiles) to the screen (so far so good)

On map drag:

  • load again via .post tiles (based on how many pixels you dragged)
  • append again the data(tiles on the screen)

Everything is working if you drag slow but if you want to drag like a crazy man the map will become a mess(it doesn't load all the tiles)

Can you provide me a better algorithm with some examples if possible or maybe some source codes (i didn't found nothing on google about these 2 games' maps)

P.S. I tried to put my example on 000webhost.com but I don't know why the json_decode() returns null .On my pc works fine.

4

2 回答 2

0

最后我创建了我想要的地图,并且我没有为每个拖动事件使用 ajax 请求。我只是将整个地图数据加载到一个 javascript 数组中。

这是预览(图片不是我的所以我不建议使用它们) 基于瓦片的地图

这是github 上的REPO

于 2013-04-08T20:12:45.900 回答
0

这只是一个一般的想法。
我无法为您提供源代码,但您应该做的很简单:您应该创建一个类似“视口”的代码,而不是每次移动鼠标时都创建、附加、清除、重新附加。因此,所有图块都将被预设,然后在运行时,您只会在视口上打印大于 -MAP_TILE_SIZE 且小于屏幕宽度 +MAP_TILE_SIZE 的图块。

于 2013-02-25T20:49:11.950 回答