Click to See Complete Forum and Search --> : How to make objects collide in C#?


artistic
December 12th, 2008, 10:25 AM
I am new to graphics programming. I am having a problem that the objects do not collide and seem to go over each other.I will paste my code so you can take a look and tell me what am I doing wrong.

I am using a bounding box. C# provides a structure name RECTANGLE.

private Image cheeseImage = null;
private Image breadImage = null;
private Rectangle cheeseRectangle;
private Rectangle breadRectangle;

//In Initialize component

System.Reflection.Assembly execAssem = System.Reflection.Assembly.GetExecutingAssembly();
cheeseImage = new System.Drawing.Bitmap(execAssem.GetManifestResourceStream(@"FirstMobileApp.cheese.gif"));
cheeseRectangle = new Rectangle(0, 0, cheeseImage.Width, cheeseImage.Height);

breadImage = new System.Drawing.Bitmap(execAssem.GetManifestResourceStream(@"FirstMobileApp.bread.gif"));
breadRectangle = new Rectangle(0, 0, breadRectangle.Width, breadRectangle.Height);


//And when I put the below code, it simply doesn't collides with the other object

if (cheeseRectangle.IntersectsWith(breadRectangle))
{
goingDown = !goingDown;
}

Any help would be appreciated
Thanks

TheCPUWizard
December 12th, 2008, 11:14 AM
1) Please use code tags when posting code. You should go back and re-read the FAQ's. And please EDIT your EXISTING post before any further posting here on CodeGuru.

2) This forumis primarily for non-language specific issues. You may get better responses in the C# forum, if your problem is language specific (assumption because you posted code). Do NOT double post, ask a moderator to MOVE the thread.