2013-09-30 120 views
5

我可以使用简单的SKSpriteNode绘制矩形。但我不能在三角形,圆形等其他类型的绘画中使用两种分色。有人建议去CGPath。但我是新手,不知道画这种类型的复杂的东西。请任何人都可以用SPRITEKIT中的MULTICOLOR说明使用这些图纸的简单方法。意思是它们的上半部分是一种颜色,下半部分是第二种颜色。更简洁的说,无论是星形,矩形,三角形还是其他形状,Shape都分为两种颜色。 任何帮助将不胜感激。使用两种颜色在Spritekit中绘制矩形/圆形和三角形。 。 。

谢谢。

回答

8

可以使用SKShapeNode绘制在精灵试剂盒形状,但是每个SKShapeNode被限制为一个线颜色(则strokeColor)和一个填充颜色。

但是,您可以创建一个包含两个SKShapeNodes儿童,每一个不同的strokeColors/fillColors定制SKNode子类。

像这样的事情会为绘制一个正方形,用自定义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; 
} 
+0

正如我说,图纸将充满两种颜色。我如何填写行。这必须是矩形或其他的一次。我承认这是制作绘图的方法,但我只是问我该如何填充它? – Programmer

+0

我不知道你的意思。你能上传你想要的样子吗? – Greg

+0

我已在此发布图片样本。 [链接](http://postimg.org/image/je24gs8yv/) – Programmer