Adam Carter
Adam Carter

Reputation: 4844

Creating a CGPath from a UIImage

I’m using SpriteKit for my game, and would like a type of per-pixel physics. In iOS 7, (I think) the only way to do this is with the bodyWithPolygonFromPath: method. My images are a bit complicated though, so, instead I’d like to create a more basic shape of my image then create a path from that alpha image.

Is is possible to turn my image in to a CGPath to use for the physics body?

I know in iOS 8 there are APIs to do this, but I want my game to run on iOS 7 too.

Upvotes: 2

Views: 1282

Answers (1)

JRam13
JRam13

Reputation: 1132

You can use PhysicsEditor(PE) like someone mentioned or you can use SKPhysicsBody Path Generator. All you need to do is drag and drop your sprite, and it will generate the objective-c code for you.


EDIT:

I have used PE before for cocos2d games, but I have no idea how to use PE with SpriteKit (since PE doesn't natively support SpriteKit just yet).

Upvotes: 1

Related Questions