0

I'm using Xcode, SKSpriteKit and am creating a game.

I need my program to draw a quadrilateral in a function.

    -(void) DrawQuad {
    //Draw Quadrilateral here with points (a,b), (c,d), (e,f), (g,h)
    }

I have already tried other links/help but for some reason, the code I paste doesn't work.

For example, at: Draw Rectangle/ Circle and Triangle in Spritekit with Two Colors. . ., I try copy and pasting that function into my code (In the .mm file). It doesn't work:

enter image description here

enter image description here

Even making the suggested changes in the program still doesn't resolve the issue.

4

1 回答 1

1

SKShapeNode绘制由Core Graphics路径定义的形状。如果我没记错的话, UIBezierPath 不是其中的一部分,但您可以使用 CGPath 代替。

看这个示例代码:

SKShapeNode *myNode = [[SKShapeNode alloc] init];
myNode.position = CGPointMake(300,300);
myNode.zPosition = 100;
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathMoveToPoint(myPath, nil, 0, 0);
CGPathAddLineToPoint(myPath, nil, 0, 100);
CGPathAddLineToPoint(myPath, nil, 100, 100);
CGPathAddLineToPoint(myPath, nil, 100, 0);
CGPathAddLineToPoint(myPath, nil, 0, 0);
myNode.path = myPath;
CGPathRelease(myPath);
myNode.strokeColor = [SKColor redColor];
[self addChild:myNode];
于 2015-04-15T15:35:41.527 回答