Code:
For Each label In Panel1.Controls
If GetType(Label).ToString = "System.Windows.Forms.Label" Then
CheckOverlap(label) ' a function elsewhere to check for collision
End If
This is inside a timer that moves my bullet up. It checks for collision on every movement of the bullet.
Code:
Function CheckOverlap(ByVal label)
Laser.Left = PictureBox1.Left
Laser.Right = PictureBox1.Left + PictureBox1.Width
Laser.Top = PictureBox1.Top
Laser.Bottom = PictureBox1.Height + PictureBox1.Top
AlienShip.Left = label.Left
AlienShip.Right = label.Left + label.Width
AlienShip.Top = label.Top
AlienShip.Bottom = label.Height + label.Top
If Laser.Right >= AlienShip.Left And Laser.Left <= AlienShip.Right And Laser.Bottom = AlienShip.Top - 5 Or Laser.Top = AlienShip.Bottom - 5 And Laser.Right >= AlienShip.Left And Laser.Left <= AlienShip.Right Then
Laser.Top = Laser.Top - 1
LaserFired = 0
End If
End Function
See I need to find *which* label it hit inside the if statement.