Reputation: 596
Is there a way I can export a physicsbody polygon path from PhysicsEditor (from Code and Web) as a CGPath? I feel there may be an easier way than for me to manually convert from (72, 429) , (77, 423) , (77, 425) , (-64, 437) ...
into [CGPoint(x: 72, y: 429), CGPoint(x: 77, y: 423) ...
etc. I can't find much info online. Thanks
Edit: I have figured out a way to do this in the xcode playground using string.replacingOccurrences(of:...
Upvotes: 1
Views: 76
Reputation: 16847
You can make your own extractor template and extract it to a plist of strings that could then be read by NSArray.
Now I am not going to go over that process, you can check out the resources over at Code And Web to see how to make that.
The string must be in {x,y}
format
Once you have it in the plist format, you can then load it into an NSArray
, and iterate through the array like so:
let polygon = CGMutablePath()
polygon.move(to:CGPoint.zero)
let array = NSArray(fileNamed:"polygon")
for strPoint in array
{
let point = CGPointFromString(strPoint)
polygon.addLine(to:point)
}
polygon.closeSubpath()
'Note if you need an example of how the plist should look like for an NSArray, you can create one via the New File
method, and then open it in an XML capable text editor.
Upvotes: 2