简体   繁体   English

cocos2d中的碰撞检测

[英]collision detection in cocos2d

i want to detect collision detection two times in same row. 我想在同一行中检测两次碰撞检测。

for example:-(see the below image) 例如:-(见下图)

the ellipse and rectangle or detcted. 椭圆和矩形或有缺陷。 after that my ellipse will travelling in the straight line path to down and detect the another rectangle. 之后我的椭圆将沿直线路径向下行进并检测另一个矩形。

first one is( travelled in trajectory path ) working fine. 第一个是(在轨迹路径上行进)工作正常。 second one i want to pass in straight line to down for collision detection. 第二个我想通过直线向下传递以进行碰撞检测。

how to do this process. 怎么做这个过程。

替代文字

Use the Box2D physics library for collision detection. 使用Box2D物理库进行碰撞检测。 It is by far the best option in your case and elegantly supported in Cocos2d. 它是目前最好的选择,在Cocos2d中得到了优雅的支持。

See here: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone 见这里: http//www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone

As i know cocos2d have no collision detection of sprites because it's not a phys engine. 我知道cocos2d没有sprite的碰撞检测,因为它不是一个物理引擎。 If you want the collision be detected automatically use Box2D or chipmunk physics engine, supported by cocos2d. 如果要自动检测碰撞,请使用cocos2d支持的Box2D或chipmunk物理引擎。

If the number of object you want to check for collision is small you can just run over your object and check if some of them (or only one if it's enough for you) overlaps with the others. 如果要检查碰撞的对象数量很少,则可以在对象上运行并检查其中一些(或者只有一个,如果它足够)与其他对象重叠。

Making more complex collision detection will bring you for writing a collision detection part of a physics engine. 进行更复杂的碰撞检测将为您编写物理引擎的碰撞检测部分。 It's much simpler to use en existing one 使用现有的更简单

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

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