|
-
Jul 26th, 2001, 02:36 PM
#1
Thread Starter
Hyperactive Member
collision detection helpp!!!!!!!
ok, say i have a picture that moves around a form using the arrow keys. I also have another fixed picture in the center of the form. They are both rectangular....how do i detect a collision between the two images? and how do i make the picture that moves stop when it hits the other fixed picture???
thanks in advance
Visual Basic 6, HTML, JavaScript, learning C++
-
Jul 26th, 2001, 02:43 PM
#2
Addicted Member
You could say:
Code:
If KeyCode = vbKeyLeft Then
If Picture1.Left > Picture2.Left + Picture2.Width Then
Picture1.Left = Picture1.Left - 5
End If
End If
If KeyCode = vbKeyRight Then
If Picture1.Left + Picture1.Width < Picture2.Left Then
Picture1.Left = Picture1.Left + 5
End If
End If
If KeyCode = vbKeyUp Then
If Picture1.Top > Picture2.Top + Picture2.Height Then
Picture1.Top = Picture1.Top - 5
End If
End If
If KeyCode = vbKeyDown Then
If Picture1.Top + Picture1.Height < Picture2.Top Then
Picture1.Top = Picture1.Top + 5
End If
End If
I am assuming that picture2 is the static picture box
Last edited by hypnos; Jul 26th, 2001 at 02:54 PM.
-
Jul 26th, 2001, 02:46 PM
#3
Thread Starter
Hyperactive Member
thankssss!!!! now how do i move a picture using the arrow keys? i used to have the code but its lost in my hdd....
Visual Basic 6, HTML, JavaScript, learning C++
-
Jul 26th, 2001, 02:47 PM
#4
Addicted Member
do you mean move a picture inside the picture box?
-
Jul 26th, 2001, 02:49 PM
#5
Addicted Member
BTW, that collision code is in no way fit for use. I just typed it up really quickly while in this forum. It should give you the idea though, which is what I was intending to do.
-
Jul 26th, 2001, 02:52 PM
#6
Thread Starter
Hyperactive Member
well, i get the idea.....but how do you move a picture with arrow keys?
Visual Basic 6, HTML, JavaScript, learning C++
-
Jul 26th, 2001, 02:58 PM
#7
Addicted Member
If you want to move a picture box with the arrow keys add this code:
Code:
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then Picture1.Left = Picture1.Left - 20
If KeyCode = vbKeyRight Then Picture1.Left = Picture1.Left + 20
If KeyCode = vbKeyUp Then Picture1.Top = Picture1.Top - 20
If KeyCode = vbKeyDown Then Picture1.Top = Picture1.Top + 20
End Sub
is that what you wanted?
-
Jul 26th, 2001, 03:00 PM
#8
Thread Starter
Hyperactive Member
yep, i had something like that but it didnt work..thanks for the help
Visual Basic 6, HTML, JavaScript, learning C++
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|