I have a rudimentary collision detection function that tells me if two bounding boxes are overlapping. This post describes it well: Determine if two rectangles overlap each other? The code I use is simple and basically the same as the code from the post:
if (RectA.Left < RectB.Right && RectA.Right > RectB.Left &&
RectA.Top > RectB.Bottom && RectA.Bottom < RectB.Top )
This works fine. My problem is, I need to know whether the collision occurred on the X or the Y-axis. This can be surmised from how much the boxes overlap on either axis:
As you can see, there's more overlap occurring on the Y-axis (8 pixels) than on the X-axis (only 1 pixel). I can use this to determine the boxes are colliding on the X-axis, however, I haven't been able to come up with a concise and efficient way to do so. Any help is appreciated!