用两种颜色在Spritekit中绘制矩形/圆形和三角形...

Pro*_*mer 5 core-graphics sprite cgpath ios7 sprite-kit

我可以使用简单的SKSpriteNode绘制Rectangle.但我无法在其中绘制其他类型的图纸,如Triangle,Circle等,具有TWO SPLIT COLORS.有人建议和CGPath一起去.但我是新手,不知道画这种复杂的东西.任何人都可以通过SPRITEKIT中的MULTICOLOR说明使用这些图纸的简单方法.意思是它们的上部是一种颜色而下部是第二种颜色.更简洁地说,Shape分为两种颜色,无论是星形,矩形,三角形还是其他颜色.任何帮助将不胜感激.

谢谢 .

Gre*_*reg 8

您可以使用SKShapeNode在sprite工具包中绘制形状,但每个SKShapeNode仅限于一种颜色(strokeColor)和一种填充颜色.

但是,您可以创建一个自定义SKNode子类,其中包含两个SKShapeNodes作为子项,每个子项具有不同的strokeColors/fillColors.

这样的东西适用于自定义的SKNode,它绘制一个左上角和上红色,右下角和绿色的正方形:

- (id) init {
    if (self = [super init]) {
        SKShapeNode* topLeft = [SKShapeNode node];
        UIBezierPath* topLeftBezierPath = [[UIBezierPath alloc] init];
        [topLeftBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
        [topLeftBezierPath addLineToPoint:CGPointMake(0.0, 100.0)];
        [topLeftBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
        topLeft.path = topLeftBezierPath.CGPath;
        topLeft.lineWidth = 10.0;
        topLeft.strokeColor = [UIColor redColor];
        topLeft.antialiased = NO;
        [self addChild:topLeft];

        SKShapeNode* bottomRight = [SKShapeNode node];
        UIBezierPath* bottomRightBezierPath = [[UIBezierPath alloc] init];
        [bottomRightBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
        [bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 0.0)];
        [bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
        bottomRight.path = bottomRightBezierPath.CGPath;
        bottomRight.lineWidth = 10.0;
        bottomRight.strokeColor = [UIColor greenColor];
        bottomRight.antialiased = NO;
        [self addChild:bottomRight];
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)