문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top