Search code examples
c#silverlightsilverlight-4.0collision-detection

Silverlight Collision Detection when controls are in different canvasses/layers


For our game we have to create collision detection. The problem is that the collided objects are in different canvasses/layers, which makes collision detection by pointlocation inpossible.

Does anyone have an idea how to solve this?


Solution

  • It's hard to give a great answer without some more information, but if all your layers are the same size then you can just roll your own collision detection. All you need to know is the locations and sizes of two things to be collision detected. Then you just test to see if one rectangle intersects with the other rectangle.

    There is also a function that might be useful to use called TranslatePoint. This translates from one UIElements coordinates to another. So if you had a ball bouncing around in a smaller area of the screen with it's own local coordinate system, you could get the ball's coordinates relative to the entire screen with this function.