How to do c# collision detection?

后端 未结 4 937
难免孤独
难免孤独 2021-01-06 18:08

Are there any predefined methods in c# which allow for collision detection?

I am new to c# and am trying to get collision detection of two ellipses are there any pre

4条回答
  •  隐瞒了意图╮
    2021-01-06 18:37

    I have tested this, it worked, at least for me

    enter image description here

    var x1 = Canvas.GetLeft(e1);
    var y1 = Canvas.GetTop(e1);
    Rect r1 = new Rect(x1, y1, e1.ActualWidth, e1.ActualHeight);
    
    
    var x2 = Canvas.GetLeft(e2);
    var y2 = Canvas.GetTop(e2);
    Rect r2 = new Rect(x2, y2, e2.ActualWidth, e2.ActualHeight);
    
    if (r1.IntersectsWith(r2))
        MessageBox.Show("Intersected!");
    else
        MessageBox.Show("Non-Intersected!");
    

提交回复
热议问题