I'm building an isometric tiled game, where the terrain and objects are represented by a 2-dimensional array of lists. Depth of objects on the map is derived from the tile (and a per-tile sorting routine), the objects are updated/drawn by going over the entire map, and it is important to know whether a tile is occupied or not for interaction/collision purposes.

Now, I want to have objects that are larger than a single tile (say, a 2x2 or 2x3 object). Drawing them this way is trivial, however, there is the occupation detection requirement. Putting the same object or dummy objects into the array merely to indicate that the tiles are taken doesn't seem like an elegant solution, but neither does checking surrounding tiles for possible big objects, each time the occupation status of a tile is requested.

Is there a more elegant solution that I've overlooked?

  • \$\begingroup\$ The most reasonable solution in this case would be the former where you indicate the same object is in multiple positions in the map array. \$\endgroup\$ – AturSams Feb 17 '14 at 17:29

The most reasonable solution in this case would be the former where you indicate the same object is in multiple positions in the map array. There is nothing wrong with that. As you may realize a platform in a 2d tile based game is "one" object that is being indicated sometimes by dozens of tiles.

Checking nearby tiles for a "Large" object would be an obfuscated solution cause it will require unneeded work and lots of it if you decide to add larger objects. The collision map unlike a list of objects and their positions is required to handle (quickly and efficiently) the detection of the presence of an object in a certain position.

| improve this answer | |
  • \$\begingroup\$ I suppose the answer is then to create dummy objects that refer to the main object upon selection? Obviously, they shouldn't react to draw/update calls. A downside here is that the main object needs to be aware of the dummy objects - otherwise it can't indicate how much/what space it is taking up when moving it around. \$\endgroup\$ – Appeltaart Feb 18 '14 at 15:58
  • \$\begingroup\$ I see what you're saying. How long would it take to update? You said you were working with an array of lists.. does it mean you actually need to iterate over several lists each time? That sounds wasteful and I would probably try a 2d-hash or a plain ole' 2d-array. \$\endgroup\$ – AturSams Feb 18 '14 at 17:31
  • \$\begingroup\$ Indeed - the array contains lists of objects. As a single tile can contain multiple small objects, but there are still benefits to be had from having tiles, I chose for this approach. \$\endgroup\$ – Appeltaart Feb 20 '14 at 10:32
  • \$\begingroup\$ I see now, a 2d array of list.. I thought you meant 1d array of lists at first \$\endgroup\$ – AturSams Feb 21 '14 at 10:12
  • \$\begingroup\$ Just a cheap suggestion... I had the same problem and resolved it by assigning each object an Area (which in the case of 1-tile objects was just this). Then I assign the main object to the primary tile and just the Area to the others. \$\endgroup\$ – Marco Bolis Dec 24 '14 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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