Skip to main content

Pixel Is there a good way to get pixel-Perfect Collision Detectionperfect collision detection in XNA?

deleted 38 characters in body
Source Link
ashes999
  • 11.3k
  • 9
  • 61
  • 95

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

EditWARNING: I'm sure there's an elegant hack solution to this. XNA is effectively 3DIf you're using the sample code from the link from the answer below, so something as simple as "cast a line through this position atbe aware that (x, y) and see ifthe scaling of the matrix is commented out for good reason. You don't need to uncomment it intersects both sprites." That's the kind of direction of solution I'm looking towardsout to get scaling to work.

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

Edit: I'm sure there's an elegant hack solution to this. XNA is effectively 3D, so something as simple as "cast a line through this position at (x, y) and see if it intersects both sprites." That's the kind of direction of solution I'm looking towards.

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

WARNING: If you're using the sample code from the link from the answer below, be aware that the scaling of the matrix is commented out for good reason. You don't need to uncomment it out to get scaling to work.

Tweeted twitter.com/#!/StackGameDev/status/95697946196189184
added 260 characters in body
Source Link
ashes999
  • 11.3k
  • 9
  • 61
  • 95

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

Edit: I'm sure there's an elegant hack solution to this. XNA is effectively 3D, so something as simple as "cast a line through this position at (x, y) and see if it intersects both sprites." That's the kind of direction of solution I'm looking towards.

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

Is there a well-known way (or perhaps reusable bit of code) for pixel-perfect collision detection in XNA?

I assume this would also use polygons (boxes/triangles/circles) for a first-pass, quick-test for collisions, and if that test indicated a collision, it would then search for a per-pixel collision.

This can be complicated, because we have to account for scale, rotation, and transparency.

Edit: I'm sure there's an elegant hack solution to this. XNA is effectively 3D, so something as simple as "cast a line through this position at (x, y) and see if it intersects both sprites." That's the kind of direction of solution I'm looking towards.

Source Link
ashes999
  • 11.3k
  • 9
  • 61
  • 95
Loading