简体   繁体   English

如何检查对象是否与数组中的每个对象发生冲突?(图片框)

[英]How do I check if an object collides with every object in an array?(Picture boxes)

High school student here and I'm pretty rusty on my code. 高中生在这里,我对自己的代码非常生疏。 Okay, I have to have an image scroll along, and if it hits an object(in this case both are picture boxes), it resets. 好的,我必须沿着图像滚动,如果它碰到一个对象(在本例中都是图片框),它将重置。

The problem is when it gets to the If statement below, it won't work saying " 'bounds' is not a member of 'system.array' " 问题是,当到达下面的If语句时,说“'bounds'不是'system.array'的成员”将不起作用。

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

The error is the Objects.bounds 错误是Objects.bounds

    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 

Why doesn't this work? 为什么不起作用? Why? 为什么? Is there a simpler way of checking all of this, such as calling a function which checks the bounds individually? 有没有更简单的方法来检查所有这些内容,例如调用一个函数来单独检查边界?

Use Linq. 使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM