VB.NET + Java – Collision Detection

This post was written by Brandon on December 22, 2008
Posted Under: Java,Visual Basics .NET

I got a email asking how to do collision detection in Java. While i'm at it, I might as well review collision detection in VB.NET, that was used for the gravity example (http://bncapps.com/?p=91)

Visual Basics .NET

 
If Object1.IntersectsWith(Object2) Then
'do whatever
End If
 

Object1 and Object2 can be anything from labels or shapes. This code can be placed in a timer to continuously check if there's a intersection occurring and act accordingly.

Java
In Java, the code is almost the exact same.

 
  if (Object1.intersects(Object2.getBounds())){
//do stuff
 }
 

The use is the same and only executes the if statement if they are touching.

And that's it, hope it helps.

If you have any more suggestions, don't hesitate to contact me

Add a Comment

required, use real name
required, will not be published
optional, your blog address