作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我知道已经回答了非常类似的问题,但我还没有看到特别提出这个问题。
我有一个椭圆形和一个矩形,我想检测它们是否相交。我知道你可以用两个矩形来做到这一点,如下所示:
if (new Rectangle(x1, y1, w1, h1).intersects(new Rectangle(x2, y2, w2, h2))) {
//code here for when collision occurs.
}
是否可以用这样的椭圆形来做到这一点?
if (new Oval(x1, y1, w1, h1).intersects(new Rectangle(x2, y2, w2, h2))) {
//code here for when collision occurs.
}
提前致谢!
最佳答案
当我搜索 Oval 类时,我没有看到 Oval 类,因此我将使用 Ellipse 作为示例。如果您查看文档 here您将看到 Shape
类的文档。
此类由 Rectangle
和 Ellipse
扩展,并且还包含一个 intersect(Shape, Shape)
方法,因此您将能够对这两个对象使用 intersect。
如果您的 Oval
类和 Rectangle
类都从您的场景中的 intersect(Shape, Shape)
继承自,它也适用于您的场景。
关于java - 有没有办法将 Oval 对象与 intersects() 函数一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56138290/
我是一名优秀的程序员,十分优秀!