Per-Pixel collision code

后端 未结 1 1540
情深已故
情深已故 2020-12-22 07:10

I tried to understand the code that checks the collision between two objects in the game - per pixel collision. The code is:

/// 
/// Determin         


        
相关标签:
1条回答
  • 2020-12-22 08:11

    The Color.A property is the alpha-value of the color. 0 means completely transparent, and 255 means completely opaque.

    If one of the colors is completely transparent at the specified pixel, there is no collision (because one of the objects is not at this place, but only its bounding box).

    Only if both of them are != 0, there actually are two objects at the same place and a collision has to be handled.

    See for example this image: bb intersection

    The bounding boxes (black rectangles) intersect, but you would not consider it to be a collision between the red and yellow circle.

    Therefore, you have to check the color at the intersecting pixels. If they are transparent (white in this example), the circles themselves are not intersecting.

    This is why you have to check if the colors of the objects are transparent. If one of them is transparent, the object itself is not intersecting the other object, only its bounding box.

    0 讨论(0)
提交回复
热议问题