I am creating a little platforming game and I want to compare the bounds of one player rectangle with many rectangle elements that are my platforms. I know in WinForms I can just use a PictureBox .bounds.intersectswith()
method.
in my xaml I define my controls like this inside a gridpane called program.
<Rectangle Name="player" Tag="player" HorizontalAlignment="Left" Height="61" Stroke="Black" VerticalAlignment="Top" Width="75" Canvas.Top="332" Canvas.Left="25">
<Rectangle.Fill>
<ImageBrush ImageSource="player.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Tag="platform" HorizontalAlignment="Left" Height="82" Stroke="Black" VerticalAlignment="Top" Width="100" Canvas.Top="398">
<Rectangle.Fill>
<ImageBrush ImageSource="purplebrick.png"/>
</Rectangle.Fill>
</Rectangle>
and then I want to compare the bounds of the player with the about 50 platforms.
foreach (Rectangle x in LogicalTreeHelper.GetChildren(program))
{
if (x is Rectangle && x.Tag.ToString() == "platform")
{
if(player.intersectswiht(x) // problem area
iv been using this question Bounds.Intersect for WPF as a reference but do I need to name every rectangle element and create an actual reference to be able to use its intersect with function?
or should I just compare every elements dimensions (canvas.top ect)but that would only give me the edges value not a range for if they overlap correct?