Search code examples
ioscocos2d-iphonebox2dshapesvertex

Get Image Vertices for Box2D?


I am trying to get the vertices for an image I have in my app. Currently I have been using Vertex Helper but I want to make my vertex shape a bit wider. However, I am not sure how do this with hard coded values.

I have tried to use Physics Editor but it just outputs a plist which I don't think I can use with the iOS Cocos2D. Anyway what program can I use to get the exact shape I'm looking for and getting the values for that shape for Box2D?

Also just to provide a little more context this is an example of the initialization of a vertex shape that I am talking about:

b2Vec2 verts[] = {
            b2Vec2(-25.6f / PTM_RATIO, 50.7f / PTM_RATIO),
            b2Vec2(-20.6f / PTM_RATIO, -48.0f / PTM_RATIO),
            b2Vec2(27.3f / PTM_RATIO, -48.0f / PTM_RATIO),
            b2Vec2(21.5f / PTM_RATIO, 51.5f / PTM_RATIO),
            b2Vec2(-26.8f / PTM_RATIO, 49.8f / PTM_RATIO) };
        spriteShape.Set(verts, num);

Any advice, tips, or ideas would be highly appreciated!


Solution

  • I decided to go ahead and use PhysicsEditor with the GB2ShapeCache files. I am going to have to do some subclassing and modification though of the class because it is not natively made to work with b2ContactListeners I guess. Anyway can correct me if I am wrong though.