Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
6  
The "best" approach would probably be one that works. What problems are you having with your current one? –  Nicol Bolas Mar 28 '12 at 5:35
    
This is what I got as a prototype. jsfiddle.net/mac1175/p2GqB/16 –  mitch Mar 28 '12 at 10:13
    
@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. –  mitch Mar 28 '12 at 10:17
    
Question subject and body talk of completely different things. –  Jari Komppa Jan 8 '13 at 10:01
    
Following Jari Komppa's comment, i strongly suggest a clarification in both title and body. –  GameAlchemist Feb 12 '13 at 5:47
show 1 more comment

closed as too broad by Vaughan Hilts, Seth Battin, Anko, Sean Middleditch, Jari Komppa Apr 10 at 17:16

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.

1 Answer

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:

enter image description here

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:

enter image description here

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.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.