Cocos2d-x V3 accurate physics body shape with PhysicsEditor
Create a physics file
First of all, create a physics file with PhysicsEditor. Just drag image(s) to the left pane.
- Set the Exporter to
Chipmunk generic (PLIST) - BETA
- Set the Relative both values to
0.5to move the anchor point to the center
- Click on that icon
You will see the face is highlighted, PhysicsEditor helps you to generate vertices/points of the image.
You can change the tolerance value (by default is
1), of course, the lower the better, but will be slower (theoretically).
Once you have done, the image is now highlighted with its shape.
Publish it as
.plist file. You have done the part.
Add the physics file to Xcode project
Drag the published file to Xcode file pane and select
Create folder references.
It will looks like this.
Test it out in code
Before actually use the physics file, let's try with the default API. Edit HelloWorldScene.cpp
It is rectangle.
Update AppDelegate.cpp, add the physics file you generated just now to cache
Then in HelloWorldScene.cpp
Then finally you get
Although it is not perfect yet, but it basically solve the issue that I faced. Will continue to seek for solution to make it perfect :)
I created a demo project, please refer to Cocos2d-x-PhysicsEditor-demo.