Results 1 to 4 of 4

Thread: basic collision detection between two shapes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    19

    basic collision detection between two shapes

    is there anyway to detect collision between two shapes in a very simple way that a beginer can understand .
    my program is this :
    I have one shape ( the target ) at one end of the form and one shape ( the so called missle ) at the other end . i also have a button on the form that after i click on it the missle moves towards the target. now this is the part i want : i want the program to detect collision between them and after the missle contacts the target i want the program to do something ( like change the target's color ) to tell me that they hit each other .
    please help me. i am a beginer . the simplest form of such a program !!!!!!!!!!
    thankyou

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    You will have to check the Left, and Top propertys of the shapes.

    To see if shape1s left side hits shape2 on the right side...write something like this....

    VB Code:
    1. If (Shape1.left + Shape2.Width) > Shape2.left and (Shape1.left + Shape1.width) < (Shape2.left + Shape2.Width) then
    2.    'Check the Top property...


    then you have to write something for the top property....

    This is not the only way to do it. But if you try this way....a good suggestion is to draw the colision on a paper, then you can see what properties to check for colision from what side......

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    19
    thanx for the suggestion and the sample code .
    but could you explain a bit more of what you mean by : what properties to check for colision from what side .
    and if we were supposed to give a grade from 1 to 10 to this form of detection in vb what would its grade be. i mean that how much useful it is ( the grade? ) ?
    thanx again.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Since this question has bean asked so many times...I'm not sure if it's worth using that much time. So I did a quick search on the site...have a look at this...

    http://www.vbforums.com/showthread.p...hreadid=177612

    If you have more questions after reading that..then feel fre to ask again...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width