shena forga

shena forga

  • NA
  • 7
  • 0

C# Pixel Collision

Sep 17 2009 8:55 PM
Ok I have two picture boxs I want to colldie. I have this code for it however I need to make this code into Pixel collision so they acutally collisde and not just the boxs around them.

private void pb_plane2_MouseMove(object sender, MouseEventArgs e)

{

if (moveplane2)

{

pb_plane2.Top = pb_plane2.Top + (e.Y - currentY);

pb_plane2.Left = pb_plane2.Left + (e.X - currentX);

}

if (movingpic)

{

int plane1L, plane2L, plane1R, plane2R, plane1T, plane2T, plane1B, plane2B;

collis = true;

plane1T = pb_plane1.Top;

plane2T = pb_plane2.Top;

plane1B = pb_plane1.Top + pb_plane1.Height;

plane2B = pb_plane2.Top + pb_plane2.Height;

plane1L = pb_plane1.Left; plane2L = pb_plane2.Left;

plane1R = pb_plane1.Left + pb_plane1.Width;

plane2R = pb_plane2.Left + pb_plane2.Width;

//check if there is a collision - collis = flase

if (plane1T > plane2B) collis = false;

if (plane1B < plane2T) collis = false;

if (plane1L > plane2R) collis = false;

if (plane1R < plane2L) collis = false;

if (collis)

{

//note: there is a lag time when this file plays and when the oops shows up

//taking out the sound file gets rid of the lag

tb_collision.Text = "OOPS!!!";

// sound clip

}

}

}

This code works just fine I just need to know how to code it from this to pixel so it colides with each plane and not the boxs around them :)


Answers (1)