I have been delving in to Apple's new Sprite Kit, and been using it for a while now.
However I ran into an issue when trying to draw a curved path for an SKShapeNode
. It just appears to draw a straight line instead.
Here is a very simple example of the issue I am having - experimenting with drawing a CGPath
for an SKShapeNode
:
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0);
CGPathAddLineToPoint(path, NULL, 50, -100);
CGPathCloseSubpath(path);
SKShapeNode *shape = [[SKShapeNode alloc]init];
shape.path = path;
[self addChild:shape];
CGPathRelease(path);
Here is my ASCII art of what it is doing (Sorry I don't have enough reputation to post an actual image yet):
---------------------------------------------------------------------------------
| EXPECTED RESULT | ACTUAL RESULT |
---------------------------------------------------------------------------------
| | |
| __----__ | |
| / \ <- Curve | ? |
| / \ | ____________ |
| \ / | \ / |
| \ / | \ / |
| \ / | \ / |
| \ / | \ / |
| \ / | \ / |
| \/ | \/ |
---------------------------------------------------------------------------------
As you can see, it is not drawing the curve that I want from this line of code:
CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0);
I have tried using CGPathAddArcToPoint(...)
, which works, and would be a good substitute in this example. However, for my actual needs, I need to be able to draw a quad curve.
The CGPath seems to be drawing everything appropriately apart from CGPathAddQuadCurveToPoint(...)
and also, CGPathAddCurveToPoint(...)
- where they just draw a straight line between the points instead.
Does anyone have any idea what the issue is? Or is this a bug with Sprite Kit?
That "y" should be the height of your curve, try giving it a non zero value. By giving a coordinate it cannot know how steep the curve should be. So that is the height
CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 30);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With