如何检查一个对象是否与数组中的每个对象碰撞?(图片框)

问题描述:

高中生在这里,我的代码很生锈。好吧,我必须有一个图像滚动,如果它击中一个对象(在这种情况下,这两个都是图片框),它重置。如何检查一个对象是否与数组中的每个对象碰撞?(图片框)

问题是,当它得到下面的if语句,它不会工作,说:“‘界限’不‘的System.Array’中的一员”

If PtbIcon.Bounds.IntersectsWith(objects.Bounds) Then 

错误是对象。边界

If PtbIcon.Bounds.IntersectsWith(objects.Bounds) Then 
     t = t + 1 
     PtbIcon.Location = New Point(29, 236) 
     'resets when you die, sets the score 
    End If 
    lblScore.Text = "Your Score Equals" & t 

End 

为什么不能正常工作?为什么?有没有更简单的方法来检查所有这些,比如调用一个单独检查边界的函数?

+0

我们不知道如何声明'objects'(真正的坏名字),但无论它是什么,它似乎都不是一个具有bounds属性的Type。请阅读[问]并参加[旅游] – Plutonix

使用Linq。

Dim t As Integer = 0 

PtbIcon.All(Function(pb As PictureBox) As Boolean 
    ' Checking goes here with pb 
    ' Return True if you want to go through all of them 
End Function) 

lblScore.Text = "Your Score Equals" & t