iPhone SDK 中的碰撞检测:CGRectIntersectsRect 不准确

发布于 2024-08-07 12:13:58 字数 214 浏览 1 评论 0原文

当两个对象要发生碰撞时,我使用 CGRectIntersectsRect 检查它们。 然而,在它返回“是”(它们碰撞)之前,它们已经重叠了。 还有其他方法来检测和解决冲突吗?

我的解决方法是比较它们的 Y 轴,并在检测到它们发生碰撞后将对象移得远离彼此。

另外,我的一个物体是一个圆,iPhone SDK还有其他函数可以更好地检测碰撞吗? (目前我将圆视为矩形,因为它的框架是矩形)

When there are two objects going to collide, I check them with CGRectIntersectsRect.
However, before it returns me with YES (they collide), they are already overlapped.
Is there any other way to detect and resolve collision?

My workaround is to compare their Y axis and move the object far apart from each other, once they are detected collision.

Also, one of my objects is a circle, is there any other functions for iPhone SDK to detect the collision better? (currently I treat the circle as a rectangle, as its frame is a rectangle)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长梦不多时 2024-08-14 12:13:58

您可以使用 CGPath 来检测不规则刚体的碰撞。请参阅http://bobueland.com/cocos2d/?p=379

You can use CGPath to detect collission for irregular rigid bodies. See http://bobueland.com/cocos2d/?p=379

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文