I've completed the per-pixel collision detection for a small side-scroller game, for learning purposes using a Lazyfoo.net tutorial, and I am wondering if it is a good method for detecting collision in an isometric game consisting of a pure 2D world.

My plan is described in this picture:

The tile starts with a bounding box, and applies per-pixel rectangles.

As you can see, I want to start with bounding boxes, and if I collide with it I start iterating through the tiles rectangles (19, in this case) for better precision. Is it a good way to handle collisions in this type of game? If not, what would be a suitable alternative?


1 Answer 1


The problem with per-pixel collision detection is that 1. it can be very slow and 2. your graphic design can have a lot more impact on your game mechanics than you would like. It is usually better to try to approximate the collision zones of the objects in your game with simple geometrical shapes.

The last time I made a game with an isometric perspective, I found it very useful to calculate all the game mechanics in orthogonal perspective. So on the game logic layer, all tiles were still rectangular. The transformation of all the orthogonal logic coordinates into the isometric screen perspective didn't happen before the rendering loop. That made many things a lot easier.

But if you really want to handle everything in screen coordinates, then you don't have bounding boxes, you have bounding rhombuses. Fortunately, these are not much more difficult to check for collision with each other than boxes.

  • The distance between two points in the upleft -> downright diagonal is abs((x1 + y1) - (x2 + y2)).
  • The distance between two points in the upright -> downleft diagonal is abs((y1 - x1) - (y2 - x2))
  • Note that if your tiles are not as wide as they are high, you need to multiply all the x-coordinates in the above two formulas with half your tile-width and all the y-coordinates with half your tile-height.
  • You have a collision in the same situation where you have a collision between two boxes: If the absolute value of the difference on both diagonals is smaller than the sum of the distance between center and edge of both rhombuses on the respective axis. Or in code, if both distances are smaller than sqrt(tilewidth * tilewidth + tileheight * tileheight) (which is, as you might notice, a constant you can hardcode).
  • \$\begingroup\$ Thanks! I´ve got some additional questions : 1. About the speed of per-pixel, do you think i should avoid this CD at all in the future? (actually i wanted to use it in my projects) 2. When you think all tiles were still rectangular, you you mean you had top-down tiles? \$\endgroup\$
    – Pins
    Commented Mar 12, 2017 at 9:24
  • \$\begingroup\$ 1. That depends on the game, but I rarely encounterd situations where it was really beneficial. 2. The tiles were rectangular on the game logics layer. The graphics layer then drew the rectangular game world in an isometric perspective. Remember that how you calculate the game logics and how you visualize them to the player are two different thing. \$\endgroup\$
    – Philipp
    Commented Mar 12, 2017 at 10:14

You must log in to answer this question.

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