To start off I am just getting started with game programming so please take it easy on me. I have decided to go with cocos2d-x 3 using c++ so that I can build it for multiple platforms with one code base. I have built a little game with where collision is working but I don't think I am doing it right and most of the tutorials are for old versions and don't quite explain the collision part to my understanding. I have 2 problems:
1.) The objects are hitting in a rectangle but I need them to hit in a circle.
2.) Detecting collisions.
Here is the code:
CCRect ballRect = ball->getBoundingBox();
CCRect enemyRect = enemy->getBoundingBox();
if(ballRect.intersectsRect(enemyRect)){
//collision
}
If someone could please help me out that would be great. I would be open to some tools to use or tutorials that I could follow along with that explain how all this works. Also the other odd thing that I found is I had to pull in code for physics editor from here https://github.com/CodeAndWeb/PhysicsEditor-Cocos2d-x-Box2d in order to get the "fixtures" in Box2D to load from the plist that physics editor exported. I don't know if that is right I would have thought Box2D could load it itself (I could be wrong here as well because I just don't know). Any help on the matter at all is greatly appreciated. Just trying to get this setup correctly and everything else has been a breeze. Just can't seem to figure out how to correctly define the collision rectangles and the correct way to detect the collisions.
Read though these, they may help.
It has downloadable project file for cocos2d-x. Version may be old. http://www.gmtdev.com/blog/2011/08/19/how-to-use-box2d-for-just-collision-detection-with-cocos2d-x/10
This is is cocos2d, which is obj-c. But he has discussed vertex helper tool that helps to create more precise collision parameter.
If you only need a circle, like a perfect circle ? you can use box2d for collision and define your body as b2Circle. Which will give you the perfect callback.
You can look at test-cpp project that comes with every cocos2d-x download for latest syntax and basic tutorial. They have test for box2d as well.