简体   繁体   English

如何使两个对象在cocos 2d中发生碰撞?

[英]How to make two object collide in cocos 2d?

        if (CGRectIntersectsRect(projectileRect, targetRects))
        {
           NSLog(@"ha ha Collision detected");
        }

     CGRect projectileRect = [player boundingBox];
     CGRect targetRects = [anEnemy boundingBox];

This is the code i am using for collision.The problem is many time the collision get not checked.If it get checked the position of collision is bottom left or right. 这是我用于碰撞的代码。问题是很多时候没有检查碰撞。如果检查了碰撞的位置是左下还是右下。

PLease advise what to do or any sample of how to do collision.ALso i am not using box or chimpunk 请告知该怎么做或如何进行碰撞的任何示例。所以我不使用盒子或黑猩猩

Make sure to check if the object has passed through the object as well. 确保检查对象是否也通过了对象。 Ray has some great tuts on all of this here 雷有一些伟大的TUTS上所有这一切在这里

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

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