0
\$\begingroup\$

I have been looking at the following question:- Tile coordinates and am thinking of using this for collision detection in my tile game.

The set up in my game is similar to this, in that there is a grid of tiles, and the sprite will move to (x,y) coordinates. However, if I were to have an object such as a box in my world that is made from multiple tiles, how would I get the collision detection to work?

Any ideas welcome.

\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

There are several ways to solve the problem of objects that are larger than your tiles.

Perhaps the easiest way is just to add the entity to every tile that it intersects with. Essentially the entity is in a wide range of tiles at any time. The is simple to implement but doesn't scale well for performance if your entities vary greatly in size.

A more flexible solution would be to use hierarchical tiles, where you have several tile sizes, and you place entities into the set of tiles that best fits their size. This works well if you have a fixed number of different entity sizes.

The most flexible solution would be a quadtree, which starts with very large tiles and recursively splits them so that they always fit the smallest object.

I drew a diagram of some simple cases to illustrate the ideas. The green boxes are the tiles that the gray object would be added to in that tile structure.

enter image description here

\$\endgroup\$
2
  • 3
    \$\begingroup\$ +1 for visual aids. However, once one makes the decision to go with the quad tree route, I would stop thinking in terms of tile grids altogether, since that abstraction is no longer useful. \$\endgroup\$ Feb 16, 2012 at 17:46
  • \$\begingroup\$ Thank you for the response, I will try this concept later on this evening. \$\endgroup\$
    – Miles
    Feb 17, 2012 at 17:52
1
\$\begingroup\$

A number of different ways to approach this, all equally valid.

One of them is to break your multi-tile box into its component single tile objects.

The reason for picking tile-based over non-tile based is because dealing with tiles simplifies a number of things.

However, it also complicates a number of things.

You've just run into one of them.

\$\endgroup\$
2
  • \$\begingroup\$ Hi, thanks for the response, I am not sure exactly what you mean by "One of them is to break your multi-tile box into its component single tile objects." \$\endgroup\$
    – Miles
    Feb 16, 2012 at 16:24
  • \$\begingroup\$ you have an object too big for a single tile, yes? so, one of the ways it to break it into a number of smaller objects, so that each object fits in its own tile. One of the alternatives to this is to track larger multi-tile objects outside of the standard tile structure, which means you are no longer strictly tile-based. If, let us say, you have a four tile sized object, you might split it into the northeast, northwest, southeast, and southwest corners of the object, and place each of the objects in separate tiles. \$\endgroup\$ Feb 16, 2012 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .