Question

I am new to core graphic in cocoa. I have a picture of a egg and I am using Sprite kit to simulation physics of free falling of an egg. I need to set the egg's physicsBody property. How to create an elliptical CGPathRef for the purpose?

For an egg shape path, I have to create an half of circle with half of oval. How to do it?

Was it helpful?

Solution

Allow me to point you to the reference documentation of CGPath, where you will find CGPathCreateWithEllipseInRect.

OTHER TIPS

Actually, I just ran into this problem in an app that I was writing to create some graphics assets.

CGPathMoveToPoint(path, nil, 10, 95);
CGPathAddLineToPoint(path, nil, (5 + SIZE) * 1.5, 95 - SIZE * 1 / 3);

CGAffineTransform t = CGAffineTransformMakeScale(1.5, 1.0);
CGPathAddArc(path, &t, SIZE + 5, 95 - SIZE * 4 / 3, SIZE, M_PI / 2, -M_PI * 5 / 4, YES);
CGPathCloseSubpath(path);

TL;DR

You have to use CGAffineTransform in order to get an arc of an ellipse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top