Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite Kit - SKShapeNode Path not drawing Quad Curve

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?

like image 262
David Williames Avatar asked Jan 22 '14 21:01

David Williames


1 Answers

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);
like image 92
OWashe Avatar answered Oct 21 '22 16:10

OWashe