Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collision Detection Question

Status
Not open for further replies.

Pitamite

Programmer
Dec 9, 2008
2
0
0
US
I have a couple questions regarding a game I'm creating in visual basic 5. I have a collision event that detects when an asteroid hits the ship and when a bullet hits an asteroid. However, the detection seems to be off a little, especially for the bullet/asteroid collision. Here is the code I have for the event:

If bulletPic.Bounds.IntersectsWith(cometImage.Bounds) Then
cometImage.Hide()
MsgBox("Asteroid Collision.")
End If

If shipPic.Bounds.IntersectsWith(cometImage.Bounds) Then
shipPic.Hide()
MsgBox("Asteroid Collision.")
End If

Is there a way to code the collision event so that the detection is more accurate? I have a feeling it's because I'm using picture boxes to hold the images, but I am not sure as to how to go about this another way. Any help would be greatly appreciated.
 
Looks like .NET to me ... try forum796

In VB6 the easiest way to achieve a similar capability is probably via the CombineRgn API call

 
Use the IntersectRect API call ... you can define a rectangle of any size, allowing you to have a much smaller target area, as accurate as a pixel.
 
Pitamite is already using (the .NET equivalent of) IntersectRect.

And I'd suggest that, if you need to resort to the API, that CombineRgn is a better solution than IntersectRect as it can deal with complex shapes, not just rectangles.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top