2013-09-30 123 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