Search code examples
iosobjective-ccocos2d-iphoneshapesoutline

Extract shape outline points from PNG image in iOS


I need to implement contours detection function in my iOS game, which I'm writing using cocos2d 2.1 For example user will provide me an image(PNG transparent):

enter image description here

So, I need detect shape polygon points and create box2d body from them, and I will able to put this image to my box2d scene.

I expect to have on output NSMutableArray with arrays of points of each polygon detected on the image. Same do PhysicsEditor, here is result of it:

enter image description here

Here is also result using VertexHelper(shows wrong way of detection, as one polygon... ):

enter image description here

Also SpriteHelper but without detection of other parts of image

enter image description here

My question is: how can I do this? What way is better and faster? I was looking for a solution in google, however I can't find any that will fit my needs...


Solution

  • Finally done this by using Chipmunk Autogeometry feature. Work like a charm.

    Just using https://github.com/slembcke/ConcaveSprite/blob/master/ConcaveSprite/ConcaveSprite.m I've saved my time...