VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Knowing whether two objects intersect

by Tarek Said (2 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This simple function let you easily know if two objects intersect. You can use it for making games or for any other purpose.

Rate Knowing whether two objects intersect

Public Function Hit(Object1 As Object, Object2 As Object) As Boolean
If Object1.Left > Object2.Left - Object1.Width And Object1.Left - Object2.Width < Object2.Left And Object1.Top - Object2.Top < Object2.Top And Object1.Top > Object2.Top - Object1.Top Then Hit = True
If Object1.Left > Object2.Left - Object1.Width And Object1.Left - Object2.Width < Object2.Left And Object1.Top - Object2.Height < Object2.Top And Object1.Top > Object2.Top - Object1.Height Then Hit = True
End Function

Download this snippet    Add to My Saved Code

Knowing whether two objects intersect Comments

No comments have been posted about Knowing whether two objects intersect. Why not be the first to post a comment about Knowing whether two objects intersect.

Post your comment

Subject:
Message:
0/1000 characters