Calculation verts for cpShape of polygons

Calculation verts for cpShape of polygons
0.0 0


Hi! I’ve recently started working on my firs game for mobile devices using this awesome engine and I’ve encounered some difficulties with creating a physical objects in my game. The thing is that when I use the following code I use cpVert array of 4 points and then the cpShape would be a rectangle.
So as it’s just a rectangle it behaves as a rectangle but the image in the space is a cloud. Basically this cloud has a non-rectangle shape and I’d like it to behave as ab object of an irregular shape. Is there any methods to calculate cpVect verts[] = array from textures or what else can I do for my purpose?

Thanks in advance!
I’d really appreciate your help!

@ CPhiysicsSprite* Sprite = new CPhiysicsSprite;

CCSize size = pNode~~>getTexture~~>getContentSize;

int num = 4;
cpVect verts[] = {
float mass = 3.0f;
cpBody *body = cpBodyNew);
body~~>p = cpv(pos.x, pos.y);
cpSpaceAddBody(m_pSpace, body);

cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);

shape~~>e = 0.5f; shape~~>u = 0.5f;
cpSpaceAddShape(m_pSpace, shape);



Cocos2d and box2d don’t have auto create physic shape with the texture.
You can create this polygons shape with many little shapes, or used physics editor cocos2d and that create many shape without you.
I use


Misha Philypchuk,

I guess this physics editor generates some plist file? I would really like to see some example of using this file. I’ve seen using this file for animation but their solution is not applicable for us. Could you please show how to use this editor in code or point me on a right link with example? Thanks!


Not sure if this thread still alive but if it is can anyone clear this field out please? I apreciate in advance!


The basics is to understand what do I make cpVect verts[] = for shape of?


GB2ShapeCache class for loading physics .plist in cocos2d-x/box2d
You can see how then create physics shape.
Look this:


Thanks alot Misha,

It seems like they’re using box2d. How about chipmunk? do you have any examples for that in C++ ?


Sorry but I have not worked with chipmunk.
But I think that working with GB2ShapeCache possible.


Yeah but not in C++ unfortunately…


Misha Philypchuk,

Do you know anybody who’s been working with Chipmunk? :slight_smile:

I’m just trying to find a solution….


No, I do not know anyone who works with chipmunk.
You can translate with Objective-C to c++, is not difficult


okay, thanks. I think we’re gonna have to write up some image self tracer on Qt that would just generate the cpVect [] array to copy-and-paste… So manually hit the edjes of a picture and save their position.


Well, making an editor didn’t resolve the problem. Still thinking of how to make polygons to behave as an adequatic physics body…