Sprite Kit - SKShapeNode Path not drawing Quad Curve

被刻印的时光 ゝ 提交于 2019-12-04 16:12:00

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/21294642/sprite-kit-skshapenode-path-not-drawing-quad-curve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!