Hello guys!
I'm trying to create a global map like in travian or other browser rts games.
The problem is that I can't load the map fully like in one ajax call, cause it will take way too long.
Proly the best way(which I also saw some of the games do it) is to load a part of the map were the player's viewpoint is.
Once the player drags the map positions, an ajax call will take place with the current player's viewpoint coordinates and the call will return the next part of the map the player went to.
The big problem I have is that I don't have a solid idea on how to actually get the player's coordinates based on his viewpoint on the map.
Any ideas will be appreciated.
Thanks .
Map System Engine
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Map System Engine
You would need to have some kind of data structure on the server that can relate your map units to some kind of multidimensional array or structure stored in the database that keeps track of the map state. Then when the player's viewport moves, all the server needs is the upper-left corner coordinate of their viewport, since all players will have a similar-sized viewports. You can extract only the data in that square, pack it in JSON and send it back to the client for the client to unpack it into the client-side map.
This is just kind of my personal preference, but for me, node and Socket.io are much better for stuff like this. Websockets are much faster than AJAX calls, and node lets you keep things in-memory rather than hitting the database for every update and state change you make (something quite difficult to do in PHP, due to the highly thread-separating nature of PHP).
This is just kind of my personal preference, but for me, node and Socket.io are much better for stuff like this. Websockets are much faster than AJAX calls, and node lets you keep things in-memory rather than hitting the database for every update and state change you make (something quite difficult to do in PHP, due to the highly thread-separating nature of PHP).
The indelible lord of tl;dr