有效处理物体之间碰撞检测的最佳方法是什么?
我对 Cocos2d、Box2d 和游戏开发都是新手,但我已经阅读了大量教程,至少在游戏设置和工作方面有一个良好的开端......
我现在需要开始添加更多的物体添加到一层,需要检查并查看我的主要头像是否以及何时会与它们中的任何一个发生碰撞。
常识似乎告诉我,我添加的物体越多,添加的情况就越多,检查fixture1是否发生碰撞例如以fixture2为例在某些时候处理器会陷入困境。
随着尸体数量的增加,是否有任何最佳实践和/或有效的算法可以使这些检查变得更加高效?
任何链接或方向将不胜感激!谢谢你!
I am new to Cocos2d, Box2d and game development all together, but I have read a good bit of tutorials to at least have a good start on a game set up and working...
Im now at the point where I need to start adding more bodies to a layer and need to check and see if and when my main avatar will collide with any of them..
Common sense seems to tell me that the more bodies I add and the more cases I add checking to see if fixture1 is colliding with fixture2 for instance will bog down the processor at some point..
Are there any best practices and/or efficient algorithms to make these checks more efficient over time as the number of bodies grow?
Any links or direction would be appreciated! thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用QuadTree来划分场景并获取需要检查的物体列表。
(有很多文章展示了 QuadTree 的工作原理,只需谷歌一下即可:D)
如果这对您来说有点复杂。然后,您可以尝试将场景划分为许多网格,并根据物体的 2d 位置进行循环以将物体放入其网格中。然后只需检查每个网格中的尸体即可。它比普通循环快得多。
https://i.sstatic.net/W5cBT.png
You can use QuadTree to divide the scene and get a list of bodies that needs to be checked.
(There are a lot of articles shows how QuadTree works, just google it:D )
And if that's a little complex for you. Then you can try to divide your scene into many grid, and make a loop to put bodies in their grid based on their 2d position. Then just check bodies in each grid. It's a lot faster than normal loop.
https://i.sstatic.net/W5cBT.png
从 iOS 7 开始,您可以使用 Sprite Kit 来处理碰撞:
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Physics/Physics.html#//apple_ref/doc/uid/TP40013043-CH6-SW14
As of iOS 7 you can use Sprite Kit to handle collisions:
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Physics/Physics.html#//apple_ref/doc/uid/TP40013043-CH6-SW14