iPhone SDK 中的碰撞检测:CGRectIntersectsRect 不准确
当两个对象要发生碰撞时,我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下一些参考:
Here are some references you might try:
您可以使用 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