In my game, I need to retrieve data of items in the visible tiles based on what tiles are visible in the viewport. I am planning to make a batch AJAX request with the visible tiles, containing image tags like Google Maps. The item information will be in JSON format.

What is the best approach for this? I currently have a class that determines the visible columns/rows and offsets relative to the visible area shown.

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.
If this question can be reworded to fit the rules in the help center, please edit the question.

6

The "best" approach would probably be one that works. What problems are you having with your current one?
–
Nicol BolasMar 28 '12 at 5:35

@NicolBolas I am trying to incorporate DOM elements in order to have some kind of backwards compatibility with older browsers (I have messed a lot with Canvas and the implementations and their performance varies, especially with mobile devices). One of the problems after I fetch the data is figuring out the offset of my items relative to the container.
–
mitchMar 28 '12 at 10:17

1 Answer
1

Actually, in most cases the client does not need to "query" the server for anything. Generally in an MMO or online game. Well, it depends on your definition of query I suppose... let us take a look at this in the context of your traditional game.

This answer assumes a stateful simulation, and not a stateless one in which a web-app might utilize (like Google Maps). This is more useful for games.

Let us suppose we have the following diagram:

The box highlighting the character to the left of is the viewport of a client. This would have been determined in one of a few ways:

The client sent up a value (resolution in a 2D game) in which they can see and the server has interpreted that and stored it

The game has a fixed viewport for all players, decided ahead of time.

Now, how can we define this viewport? This viewport is known as the area of interest. When something happens in the game world that involves other items are objects, one can query this area of interest viewport to see if it applies. For example, lets consider that "Some Player" wishes to move but our client does not know about them yet.

As long as "Some Player" does not enter the box defined on our client, the client will not know anything about "Some Player" or even that they are moving. However, lets consider this:

Suddenly, the area of interest viewport is now intersecting with "Some Player". This means that updates about and items and information about "Some Player" should now be broadcast. The following should happen when area of interests update:

If the object does not exist on the client, it should be created.

All state should be synchronized immediately and updates that are relevant should be subscribed to

Conversely, when an object leaves one can unsubscribe and optional terminate the object in client memory.

This method can apply to a wide variety of games, including top down MMOs, FPS games, and other games where information about a certain "view" needs to be hidden.