Sprite Kit-SKShapeNode路径未绘制四边形曲线 [英] Sprite Kit - SKShapeNode Path not drawing Quad Curve

查看:145
本文介绍了Sprite Kit-SKShapeNode路径未绘制四边形曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究Apple的新Sprite Kit,并且已经使用了一段时间. 但是,在尝试为SKShapeNode绘制弯曲路径时遇到了一个问题.它似乎只是画一条直线.

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.

这是我遇到的问题的一个非常简单的示例-尝试为SKShapeNode绘制CGPath:

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

这是我正在做的ASCII艺术(对不起,我没有足够的声誉来发布实际的图像):

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

我尝试使用CGPathAddArcToPoint(...),它可以工作,并且在此示例中将是一个很好的替代品.但是,出于我的实际需要,我需要能够绘制一条四边形曲线.

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.

CGPath似乎在绘制与CGPathAddQuadCurveToPoint(...)CGPathAddCurveToPoint(...)分开的所有内容,而它们只是在两点之间绘制一条直线.

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.

有人知道这个问题是什么吗?还是Sprite Kit的错误?

Does anyone have any idea what the issue is? Or is this a bug with Sprite Kit?

推荐答案

"y"应为曲线的高度,请尝试为其赋予非零值. 通过给出坐标,它无法知道曲线应有多陡.那就是高度

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

这篇关于Sprite Kit-SKShapeNode路径未绘制四边形曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆